简体   繁体   English

MediaPlayer在启动另一个活动时停止

[英]MediaPlayer stopping when starting another activity


I have a problem with the MediaPlayer. 我对MediaPlayer有问题。
I have a MediaPlayer class that starts as soon as the user launches the App, but as soon as the user taps on the "credits" button another activity starts with the credits screen, but the MediaPlayer stops playing the audio stream. 我有一个MediaPlayer类,该类在用户启动应用程序后立即启动,但是一旦用户点击“信用”按钮,另一个活动就从信用屏幕开始,但是MediaPlayer停止播放音频流。

Is there a way to avoid this? 有办法避免这种情况吗?

MediaPlayer setup: MediaPlayer设置:

player = new MediaPlayer();
player.prepareAsync();
player.setOnPreparedListener(new OnPreparedListener() {

    public void onPrepared(MediaPlayer mp) {
        player.start();
    }
});

I change page with this: 我用这个改变页面:

Intent intent = new Intent(this, Credits.class);
startActivity(intent);

Create a local service and put the MediaPlayer in that Service. 创建一个本地服务并将MediaPlayer放入该服务中。 Bind to the Service from whatever Activity needs to control the MediaPlayer. 从任何需要控制MediaPlayer的活动绑定到服务。

This is not possible since the mediaActivity will be pause. 这是不可能的,因为mediaActivity将暂停。 You might consider using a dialog instead of an intent for the credits. 您可能会考虑使用对话框而不是意向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM