Android 媒体播放器
我想在此活动中准备我的媒体播放器,准备好后我想跳转到另一个活动并在那里启动媒体播放器。它没有跳到其他活动,你能帮我吗?
public void run() {
try {
mp.setDataSource(urls.getFirst());
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
Intent i = new Intent(Start.this, RadyoBabylonActivity.class);
startActivity(i);
}
});
mp.prepare();
} catch (Exception e) {
e.printStackTrace();
}
}
});
th.start();
I want to prepare my mediaplayer on this activity and when its prepared I want to jump to another activity and start the mediaplayer there. It doesn't jump to the other activity can you help me please?
public void run() {
try {
mp.setDataSource(urls.getFirst());
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
Intent i = new Intent(Start.this, RadyoBabylonActivity.class);
startActivity(i);
}
});
mp.prepare();
} catch (Exception e) {
e.printStackTrace();
}
}
});
th.start();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信这里的问题是您试图直接从后台线程启动
Activity
。我不认为这可以直接在 Android 中完成 - 相反,您必须让 Activity 从 UI 线程启动。因此,在Android中执行此操作的方法是使用Handler
。Handler
存在于 UI 线程中,并从后台线程接收消息来执行 UI 操作,例如启动另一个Activity
。示例:
另请参阅: http://developer.android.com/reference/android/ os/Handler.html
I believe the issue here is that you are trying to start an
Activity
directly from a background thread. I do not believe this is possible to do directly in Android - instead you must have the Activity start from the UI thread. Therefore, the way to do this in Android is to use aHandler
. TheHandler
lives on the UI thread and receives messages from the background thread to do your UI actions such as starting anotherActivity
.Example:
See also: http://developer.android.com/reference/android/os/Handler.html