1
请问怎么在后台保留mediaplayer的播放状态,返回的时候怎么从原来的状态继续?
因为我是做的rtsp播放,用户下载了一些数据以后,然后用户如果想到别的程序上去,现在我是把mediaplayer销毁了,但是大家有办法不销毁mediaplayer吗?
2
我在1.6的模拟器上按动home键时候,程序回到桌面,然后再进入应用的时候还是回到刚才的界面,但是我用2.1的里程碑测试的时候,返回则是从开始界面开始执行呢?请问我该怎么返回的时候回到刚才的界面。
3
请问现在android里面有中文的语音识别api吗
请问怎么在后台保留mediaplayer的播放状态,返回的时候怎么从原来的状态继续?
因为我是做的rtsp播放,用户下载了一些数据以后,然后用户如果想到别的程序上去,现在我是把mediaplayer销毁了,但是大家有办法不销毁mediaplayer吗?
2
我在1.6的模拟器上按动home键时候,程序回到桌面,然后再进入应用的时候还是回到刚才的界面,但是我用2.1的里程碑测试的时候,返回则是从开始界面开始执行呢?请问我该怎么返回的时候回到刚才的界面。
3
请问现在android里面有中文的语音识别api吗
解决方案 »
- 如何在照片上添加文字水印(经纬度)
- 100分------------求java算法 如何在字节流中是否含有指定的四个字节呢
- eclipse工具点击DDMS里面没有内容
- 菜鸟请教一个关于EditText控制的问题,望大侠不吝赐教!
- 从后台唤醒onRestart的疑问
- Android如何转到此界面---有图有真相
- 编译android时出的问题
- 请问关于使用fragment做底部菜单,不能切换的问题
- RecyclerView Adapter 使用不同Context创建LayoutInflate有什么区别?
- 求教:实际测试中,遇到app需要显示一个页端页面如何去mock
- android mediaplayer带进度条播放点击返回时候出现IllegalStateException
- android 有什么方法能测电池电量吗?电量以毫安为单位,精度要高的
2.设置activity的启动模式android:launchMode="singleTask"
3.不知道
如果播放时用的是onbund最好用handle类来管理。不然跳转页面机会销毁。
或则直接开始服务。这样跳转就不会销毁服务。
//1.控制类
LocalBinder musicPlayerBinder=new LocalBinder();
public static MediaPlayer mediaPlayer=new MediaPlayer();
List<Map<String,Object>> listCurrentMusic=MusicSongListActivity.getMyMusic();
//2.状态类
//当前歌曲下标
private static int musicId;
//当前音乐状态
// private int currentMusicPosition=0;
//接收Intent
Intent startIntent = null;
public class LocalBinder extends Binder{
public MusicPlayerService getMusicPlayerService(){
return MusicPlayerService.this;
}
}
@Override
public IBinder onBind(Intent intent) {
return musicPlayerBinder;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
startIntent = intent;
}
@Override
public void firstSongPlay()
{
}
@Override
public boolean onUnbind(Intent intent) {
return super.onUnbind(intent);
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public IBinder asBinder() {
return null;
}
//歌曲路径和状态
public void playFile(String filePath, int mediaPlayerStatus,int currentSongsId)
throws RemoteException {
mediaPlayer.reset();
if(-1!=mediaPlayerStatus){
try {
//如果不是暂停从新设置资源
if(mediaPlayerStatus!=0)
{
musicId=currentSongsId;
Log.i("---->datasource", ""+filePath);
mediaPlayer.setDataSource(filePath);
}
mediaPlayer.prepare();
mediaPlayer.start();
// currentMusicPosition=mediaPlayer.getCurrentPosition();
//当前歌曲播放结束,接着放
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer arg0) {
try {
nextSong();
} catch (RemoteException e) {
e.printStackTrace();
}
}
});
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
//暂停
@Override
public void pause() throws RemoteException {
mediaPlayer.pause();
}
//上一首歌曲
@Override
public void previousSong() throws RemoteException {
HashMap<String,Object> currentSongMap = (HashMap<String,Object>)listCurrentMusic.get(--musicId);
// if(musicId<0)
// {
// musicId=currentSongMap.size()-1;
// currentSongMap = (HashMap<String,Object>)listCurrentMusic.get(listCurrentMusic.size()-1);
playFile(""+currentSongMap.get("musicPath"),1,musicId);
// }
// else
// {
// playFile(""+currentSongMap.get("musicPath"),1,musicId);
// }
}
//下一首歌曲
@Override
public void nextSong() throws RemoteException {
HashMap<String,Object> currentSongMap = (HashMap<String,Object>)listCurrentMusic.get(++musicId);
// if(musicId>=currentSongMap.size())
// {
// musicId=0;
// currentSongMap = (HashMap<String,Object>)listCurrentMusic.get(0);
playFile(""+currentSongMap.get("musicPath"),1,musicId);
// }else
// {
// playFile(""+currentSongMap.get("musicPath"),1,musicId);
// }
}
//歌曲持续时间
@Override
public int getDuration() throws RemoteException {
return mediaPlayer.getDuration();
}
//歌曲播放位置
@Override
public int getCurrentPosition() throws RemoteException {
return mediaPlayer.getCurrentPosition();
}
@Override
public void seekTo(int currentPosition) throws RemoteException {
mediaPlayer.seekTo(currentPosition);
}
}
void playFile(String filePath,int mediaPlayerStatus,int currentSongsId);
void pause();
void previousSong();
void nextSong();
int getDuration();
int getCurrentPosition();
void seekTo(int currentPosition);
void firstSongPlay();
}