我正在尝试为广播电台制作一个自定义播放器,他们希望从mpeg转移到aac以降低比特率(主要是针对移动用户)但是当我启动项目时,我正在针对mpeg流进行测试,当我将其更改为新的aac流时,我的播放器似乎锁定了一段时间,然后当玩家尝试在后台加载流时,UI线程被android杀死。我确实得到了一些关于它无法播放的初步错误,但也许在应用程序被杀后30秒我得到一个孤立的异步播放器在后台重新生成它的粘性通知并且流开始播放?
logcat输出在崩溃时显示这些行 I / dalvikvm:threadid = 3:对信号作出反应 I / dalvikvm:将堆栈跟踪写入'/data/anr/traces.txt'A/libc:致命信号6(SIGABRT)位于0x000008eb(代码= 0),线程32258
我看到孤立的异步任务的粘性,当我点击它时播放音频(重新获得音频焦点)但主app / ui线程显然已完全重置
产生异步任务的代码如下:
private class PlayAsync extends AsyncTask<String, Void, Boolean> {
private String url_to_play = "";
@Override
protected void onPreExecute() {
super.onPreExecute();
textView_info.setText("Buffering...");
}
@Override
protected Boolean doInBackground(String... params) {
url_to_play = params[0];
Bundle b = new Bundle();
b.putString("url", url_to_play);
Intent i = new Intent(MainActivity.this, MusicService.class);
i.putExtras(b);
try {
stopService(new Intent(MainActivity.this, MusicService.class));
} catch (Exception ex) {
//
}
startService(i);
return true;
}
@Override
protected void onPostExecute(Boolean result) {
isMuted = isMuted();
if (isMuted) {
textView_info.setText("Playing Muted!");
} else
textView_info.setText("Playing");
isBuffering = false;
}
@Override
protected void onProgressUpdate(Void... values) {
}
protected void onError(MusicService mp, int what, int extra) {
// The MediaPlayer has moved to the Error state, must be reset!
button_stop.performClick();
}
}