gpt4 book ai didi

blackberry - 如何在Blackberry中连续播放音频文件?

转载 作者:行者123 更新时间:2023-12-03 00:20:50 26 4
gpt4 key购买 nike

我想创建一个Blackberry应用程序,该应用程序可以连续播放几个音频文件。但是我创建的应用程序可以连续打开所有音频文件,但无法播放整个音频文件。谁能知道解决方案?下面是我的代码:

     package mypackage;

import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import java.lang.Class;
import javax.microedition.rms.RecordStore;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import net.rim.device.api.media.protocol.ByteArrayInputStreamDataSource;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.extension.container.*;
import net.rim.device.api.ui.UiApplication;
import java.io.IOException;

public class PlayMedia extends UiApplication{
/**
* Entry point for application
* @param args Command line arguments (not used)
*/
public static void main(String[] args){

PlayMedia theApp = new PlayMedia();
theApp.enterEventDispatcher();
}

public PlayMedia()
{

pushScreen(new PlayMediaScreen());


}
/**
* A class extending the MainScreen class, which provides default standard
* behavior for BlackBerry GUI applications.
*/
final class PlayMediaScreen extends MainScreen
{
/**
* Creates a new PlayMediaScreen object
*/
PlayMediaScreen()
{
String test1 = "Test(2seconds).mp3";
String test2 = "Test(2seconds)2.mp3";
String test3 = "Test(2seconds)3.mp3";
String test4 = "Test(2seconds)4.mp3";
String test5 = "blind_willie.mp3";
String mp3 = null;

for(int i=0;i<5;i++){
if(i == 0){
mp3 = test1;
}
else if(i == 1){
mp3 = test2;
}
else if(i == 2){
mp3 = test3;
}
else if(i == 3){
mp3 = test4;
}
else if(i == 4){
mp3 = test5;
}
play(mp3);
}
}

private void play(String mp3){

Player p = null;

InputStream stream = (InputStream)this.getClass().getResourceAsStream("/" + mp3);

try {
//p = Manager.createPlayer(source);
p = Manager.createPlayer(stream, "audio/mpeg");
p.realize();
p.prefetch();

//testing
System.out.println("Creating Players!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
System.out.println("The mp3 is " + mp3 + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

//testing
System.out.println("IO Exeception!!!!!!!!!!!!!!!!1 " + e);

//testing
System.out.println(p);

} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();

//testing
System.out.println("Media Exeception!!!!!!!!!!!!!!!!1" + e);

//testing
System.out.println(p);
}
/*
* Best practice is to invoke realize(), then prefetch(), then start().
* Following this sequence reduces delays in starting media playback.
*
* Invoking start() as shown below will cause start() to invoke prefetch(0),
* which invokes realize() before media playback is started.
*/
try {
p.start();
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();

//testing
System.out.println("Media Exeception for starting!!!!!!!!!!!!!!!!1" + e);

//testing
System.out.println(p);
}

try {
p.stop();
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
p.deallocate();
p.close();



}
}

}

最佳答案

例如,您可以将要播放的文件保存在Vector中,并创建一个队列,该队列将从播放第一个开始,到播放完毕将从第二个开始。
因此,在ur vector 中,您将拥有test1,test2,test3 ...,然后将播放test1。完成后,您将以test2开始...

关于blackberry - 如何在Blackberry中连续播放音频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7202327/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com