MediaPlayer始终在UI线程上运行

问题描述

我打算将MediaPlayer与UI线程分开。我尝试了几乎所有选项,但它仍在UI线程上运行。我从新线程执行者和现在的服务开始。我知道服务在UI Thread上运行,但是根据文档,调用prepareAsync()方法会使MediaPlayer异步运行,但仍然...

这是我的代码

@Override
public int onStartCommand(final Intent intent,int flags,int startId) {
    if (mediaPlayer == null) {
        mediaPlayer = new MediaPlayer();
         mediaPlayer.setonPreparedListener(this);
    }

    path = Uri.parse(intent.getStringExtra("path"));
    if (path != null || !path.toString().equals("null")) {
        try {
            mediaPlayer.setDataSource(MusicPlayerService.this,path);
            intent.putExtra("path","null");
        } catch (IOException e) {
            e.printstacktrace();
        }
    } else {
        duration = intent.getIntExtra("duration",0);
    }

    mediaPlayer.prepareAsync();

    return super.onStartCommand(intent,flags,startId);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)