当屏幕显示自行或手动关闭时,有没有办法阻止媒体控制器暂停。我的应用程序使用媒体控制器从互联网流式传输音频文件,因此即使屏幕关闭,我也需要它继续播放。任何帮助将非常感激。
这是我的媒体控制器类的代码:
import android.app.Activity;
import android.content.Context;
import android.view.KeyEvent;
import android.widget.MediaController;
public class WillMediaController extends MediaController {
public WillMediaController(Context context) {
super(context);
}
@Override
public void hide() {
// Do Nothing to show the controller all times
}
@Override
public boolean dispatchKeyEvent(KeyEvent event)
{
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK)
{
((Activity) getContext()).finish();
}else{
super.dispatchKeyEvent(event);
}
if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN ||
event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
// don't show the controls for volume adjustment
return super.dispatchKeyEvent(event);
}
return true;
}
}
谢谢