mirror of
https://ee.coding.net/mcontext/mContext/FunningChicken.git
synced 2024-09-18 06:24:54 +08:00
play audio
This commit is contained in:
parent
7801ac2afd
commit
a2b273d8ff
9
.idea/libraries/jl1_0.xml
Normal file
9
.idea/libraries/jl1_0.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="jl1.0">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/src/bin/jl1.0.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
@ -7,5 +7,6 @@
|
|||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="jl1.0" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
BIN
src/bin/jl1.0.jar
Normal file
BIN
src/bin/jl1.0.jar
Normal file
Binary file not shown.
60
src/com/yuxihan/MusicPlayer.java
Normal file
60
src/com/yuxihan/MusicPlayer.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package com.yuxihan;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
|
import javazoom.jl.decoder.JavaLayerException;
|
||||||
|
import javazoom.jl.player.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Java 播放音频
|
||||||
|
* @ClassName: MusicPlayer
|
||||||
|
* @Description: TODO
|
||||||
|
* @author: hyacinth
|
||||||
|
* @date: 2020年3月5日 上午12:10:53
|
||||||
|
* @Copyright: hyacinth
|
||||||
|
*/
|
||||||
|
public class MusicPlayer {
|
||||||
|
|
||||||
|
|
||||||
|
static Player player = null;
|
||||||
|
|
||||||
|
public static void main(String[] args) throws FileNotFoundException, JavaLayerException {
|
||||||
|
File file = new File("D:\\Dev\\IdeaProjects\\FunningChicken\\src\\resources\\16298209674952.mp3");
|
||||||
|
FileInputStream fis = new FileInputStream(file);
|
||||||
|
BufferedInputStream stream = new BufferedInputStream(fis);
|
||||||
|
Player player = new Player(stream);
|
||||||
|
player.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 播放 20 秒并结束播放
|
||||||
|
*/
|
||||||
|
public void play() {
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
File file = new File("D:\\Dev\\IdeaProjects\\FunningChicken\\src\\resources\\16298209674952.mp3");
|
||||||
|
FileInputStream fis = new FileInputStream(file);
|
||||||
|
BufferedInputStream stream = new BufferedInputStream(fis);
|
||||||
|
player = new Player(stream);
|
||||||
|
player.play();
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
// TODO: handle exception
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
try {
|
||||||
|
Thread.sleep(20000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
player.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
BIN
src/resources/16298209674952.mp3
Normal file
BIN
src/resources/16298209674952.mp3
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user