您好,登錄后才能下訂單哦!
一、編程規約
l 阿里的P3C開發規范插件會給出警告:
private static ExecutorService executor = Executors.newFixedThreadPool(4);
l Java多線程異步音頻播放器:
實現Java音頻播放器時,支持多線程異步播放,創建線程池時遵守《阿里Java開發手冊》規約。
代碼下載:https://github.com/rickding/HelloJava/tree/master/HelloAudio
class Player implements Runnable {
private static ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(
4,
new BasicThreadFactory.Builder().namingPattern("audio-player-pool-%d").daemon(true).build()
);
public static void asyncPlay(URL fileUrl) {
if (fileUrl == null) {
return;
}
// 播放進程
Player player = new Player();
try {
player.audioStream = AudioSystem.getAudioInputStream(fileUrl);
} catch (UnsupportedAudioFileException e) {
System.err.println(e.getMessage());
} catch (IOException e) {
System.err.println(e.getMessage());
}
executorService.execute(player);
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。