이것은 매우 수용 가능한 질문이 아니지만 나는이 시점에서 필사적이다.동기식 미디어 플레이어 javafx
빠른 탐색 및 균형 수정을 사용하는 동기식 Java 미디어 플레이어가 필요합니다.
시나리오 :
내가 루프에서 매우 짧은 (50 ~ 100 밀리 초) 미디어 파일을 재생 가지고 자바 FX 프로젝트가 있습니다. 것은 다시 시작하기 전에 기다려야하는 요구 사항입니다.
짧게 : 재생 사운드 - 특정 요구 사항이 충족 (잔액이 수정 됨) (120ms마다) -> 소리가 들리면 처음부터 재생 재생.
javafx는 내가 수정 한 미디어 플레이어를 제공합니다. 아직 더 효율성이 필요 : 사람이 올바른 방향으로 (내가 놓친 라이브러리/일)을 날 지점 수 있다면
// this method is just to show how the modified mediaplayer class is called
public void updateSoundBalance(double currentTimeInCycle) {
// control the balance of the sound
if(playingSound && mediaPlayer != null)
{
long b = System.nanoTime();
// 0 <= balance < 4. balance represents the cycle phase.
double balance = currentTimeInCycle % RADIANCE_FULL_CYCLE/RADIANCE_QUARTER_CYCLE;
boolean firstHalfCycle = balance < 2;
double quarterCycleIndex = Math.floor(balance);
long a = System.nanoTime();
if(swingingSound)
mediaPlayer.setBalance(firstHalfCycle ? 1 - balance : balance - 3);
else
mediaPlayer.setBalance(balance > 1 && balance < 3? -1 : 1);
System.out.println("C ::: sound balance = " + (System.nanoTime() - a));
if ((quarterCycleIndex == 1 | quarterCycleIndex == 3) &&
balance - quarterCycleIndex <= Settings.DEFAULT_PATTERN_SMOOTHNESS)
{
a = System.nanoTime();
if (mediaDone){
mediaPlayer.reset();
mediaDone = false;
}
System.out.println("B ::: call reset = " + (System.nanoTime() - a));
}
System.out.println("A ::: total time = " + (System.nanoTime() - b));
}
}
import java.util.concurrent.ScheduledThreadPoolExecutor;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.util.Duration;
public class MultiMediaPlayer
{
private MediaPlayer mp1, mp2;
private boolean usingMp1 = true;
private ScheduledThreadPoolExecutor seekService = new ScheduledThreadPoolExecutor(2);
private Runnable seekRun = new Runnable() {
@Override
public void run() {
try
{
long a = System.nanoTime();
if(usingMp1) {
usingMp1 = false;
mp1.stop();
mp2.play();
mp1.seek(new Duration(0));
} else {
usingMp1 = true;
mp2.stop();
mp1.play();
mp2.seek(new Duration(0));
}
System.out.println("D ::: reset sound time taken = " + (System.nanoTime() - a));
}
catch (Exception e){
e.printStackTrace();
}
}
};
public MultiMediaPlayer(Media value)
{
mp1 = new MediaPlayer(value);
mp2 = new MediaPlayer(value);
mp1.balanceProperty().bindBidirectional(mp2.balanceProperty());
mp1.onEndOfMediaProperty().bindBidirectional(mp2.onEndOfMediaProperty());
}
public void setBalance(double value){
mp1.setBalance(value);
}
public void reset(){
seekService.execute(seekRun);
}
public void play(){
if(usingMp1) {
mp1.play();
} else {
mp2.play();
}
}
public void stop(){
mp1.stop();
mp2.stop();
}
public void pause(){
mp1.pause();
mp2.pause();
}
public void setOnEndOfMedia(Runnable r) {
mp1.setOnEndOfMedia(r);
}
}
내가 감사
PS 것이 허용되는 자바 버전은 가장입니다 최신 가능