淘先锋技术网

首页 1 2 3 4 5 6 7

我的

Android应用程序的一项活动包含一个显示GrooveShark播放器网页的WebView.当用户点击网页的播放按钮时,活动会自动启动播放该轨道的默认MediaPlayer.一切正常,问题出现在用户关闭此活动和MediaPlayer时,虽然不再播放音轨,但它仍然存在……即使应用程序关闭,MediaPlayer仍然存在.杀死它的唯一方法就是强迫应用程序停止……我似乎没什么大不了的,但在某些设备中,当用户在通话后挂机时,这个“僵尸”MediaPlayer突然开始播放即使该应用程序之前已被破坏,该轨道……

这是我的活动代码的摘要:

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_song);

myWV = (WebView) findViewById(R.id.webview);

WebSettings webSettings = myWV.getSettings();

webSettings.setJavaScriptEnabled(true);

myWV.setWebViewClient(new MyWebViewClient());

myWV.setWebChromeClient(new WebChromeClient());

myWV.loadUrl(url);

}

@Override

protected void onPause() {

// TODO Auto-generated method stub

super.onPause();

myWV.onPause();

myWV.pauseTimers();

}

@Override

protected void onResume() {

// TODO Auto-generated method stub

super.onResume();

myWV.onResume();

myWV.resumeTimers();

}

@Override

protected void onDestroy() {

// TODO Auto-generated method stub

super.onDestroy();

myWV.destroy();

}

private class MyWebViewClient extends WebViewClient {

@Override

public boolean shouldOverrideUrlLoading(WebView view, String url) {

if (Uri.parse(url).getHost().equals("grooveshark.com")) {

return false;

}

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

startActivity(intent);

return true;

}

}

这是第一次播放曲目时日志显示的内容:

12-03 20:52:13.184: D/webkit(23440): euler: isUrlBlocked = false

12-03 20:52:13.794: V/MediaPlayer(23440): constructor

12-03 20:52:13.804: V/MediaPlayer(23440): setListener

12-03 20:52:13.814: D/HTML5Audio(23440): setDataSource()

12-03 20:52:13.894: V/MediaPlayer(23440): setVideoSurfaceTexture

12-03 20:52:13.894: V/MediaPlayer(23440): prepareAsync

12-03 20:52:16.144: V/MediaPlayer(23440): message received msg=3, ext1=12, ext2=0

12-03 20:52:16.154: V/MediaPlayer(23440): buffering 12

12-03 20:52:16.154: V/MediaPlayer(23440): callback application

12-03 20:52:16.154: V/MediaPlayer(23440): back from callback

12-03 20:52:16.154: V/MediaPlayer(23440): message received msg=5, ext1=0, ext2=0

12-03 20:52:16.154: V/MediaPlayer(23440): New video size 0 x 0

12-03 20:52:16.154: V/MediaPlayer(23440): callback application

12-03 20:52:16.154: V/MediaPlayer(23440): back from callback

12-03 20:52:16.154: V/MediaPlayer(23440): message received msg=1, ext1=0, ext2=0

12-03 20:52:16.154: V/MediaPlayer(23440): prepared

12-03 20:52:16.154: V/MediaPlayer(23440): callback application

12-03 20:52:16.154: V/MediaPlayer(23440): back from callback

12-03 20:52:16.184: E/MediaPlayer(23440): mOnVideoSizeChangedListener is null. Failed to send MEDIA_SET_VIDEO_SIZE message.

12-03 20:52:16.194: I/MediaPlayer(23440): Don't send intent. msg.arg1 = 0, msg.arg2 = 0

12-03 20:52:16.194: I/MediaPlayer(23440): mOnPreparedListener. Send MEDIA_PREPARED message.

12-03 20:52:16.194: D/HTML5Audio(23440): onPrepared()

12-03 20:52:16.214: V/MediaPlayer(23440): getDuration

12-03 20:52:16.224: V/MediaPlayer(23440): seekTo 0

12-03 20:52:16.224: V/MediaPlayer(23440): getDuration

12-03 20:52:16.224: V/MediaPlayer(23440): message received msg=4, ext1=0, ext2=0

12-03 20:52:16.224: D/HTML5Audio(23440): play() called. mState = 2

12-03 20:52:16.224: V/MediaPlayer(23440): Received seek complete

12-03 20:52:16.224: V/MediaPlayer(23440): All seeks complete - return to regularly scheduled program

12-03 20:52:16.224: V/MediaPlayer(23440): callback application

12-03 20:52:16.224: V/MediaPlayer(23440): back from callback

12-03 20:52:16.244: V/MediaPlayer(23440): start

12-03 20:52:16.264: D/HTML5Audio(23440): play() - start()

12-03 20:52:16.284: I/MediaPlayer(23440): mOnSeekCompleteListener. Send MEDIA_SEEK_COMPLETE message.

12-03 20:52:16.464: V/MediaPlayer(23440): isPlaying: 1

12-03 20:52:16.714: V/MediaPlayer(23440): isPlaying: 1

....

最后,一旦活动结束,这就是日志永远显示的内容

12-03 20:52:36.164: V/MediaPlayer(23440): message received msg=3, ext1=100, ext2=0

12-03 20:52:36.164: V/MediaPlayer(23440): buffering 100

12-03 20:52:36.164: V/MediaPlayer(23440): callback application

12-03 20:52:36.164: V/MediaPlayer(23440): back from callback

12-03 20:52:36.244: V/MediaPlayer(23440): isPlaying: 0

12-03 20:52:36.494: V/MediaPlayer(23440): isPlaying: 0

12-03 20:52:36.744: V/MediaPlayer(23440): isPlaying: 0

12-03 20:52:36.994: V/MediaPlayer(23440): isPlaying: 0

12-03 20:52:37.164: V/MediaPlayer(23440): message received msg=3, ext1=100, ext2=0

12-03 20:52:37.164: V/MediaPlayer(23440): buffering 100

12-03 20:52:37.164: V/MediaPlayer(23440): callback application

12-03 20:52:37.164: V/MediaPlayer(23440): back from callback

12-03 20:52:37.244: V/MediaPlayer(23440): isPlaying: 0

12-03 20:52:37.504: V/MediaPlayer(23440): isPlaying: 0

12-03 20:52:37.754: V/MediaPlayer(23440): isPlaying: 0

12-03 20:52:38.004: V/MediaPlayer(23440): isPlaying: 0

....

我需要找到一种方法来检索“僵尸”MediaPlayer并停止它……

非常感谢