1

当我的自定义视图失去焦点时(当按下 LockScreen 按钮时)我试图播放/暂停音乐到应用程序以后的音乐不播放。任何人都可以帮助我或告诉我我缺少什么 Api 级别是 8-16。提前感谢

公共类 StartGameActivity 扩展 BaseActivity 实现 OnFocusChangeListener { 私有 PuzzleView 拼图视图;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // custom View for activity set to focusable(true), & focusable
    // inTouchmode(true)
    puzzleview = new PuzzleView(this);
    puzzleview.setOnFocusChangeListener(this);
    setContentView(puzzleview);
}

protected void onResume() {
    super.onResume();

}

    protected void onPause(){
            super.onPause();
            StopMusic();
    }


@Override
public void onFocusChange(View v, boolean hasFocus) {
    if (hasFocus) {
        Initialize_Music_Player():
    }
    if (!hasFocus) {
        StopMusic();
    }
}

}

4

0 回答 0