0
サービスを拡張するメディアプレーヤークラスの停止に問題があります。私はstopをうまく呼び出すことができますが、stopService(Intent)を使用しようとすると強制終了します。私はコンテキストに関連するログにnullpointer例外を取得します。私はこれについてウェブ上のドキュメントを見つけることができません。ここで私が試したコードの一部です:OnAudioFocusChangeListenerのサービスを停止する場合= AudioManager.AUDIOFOCUS_LOSS
static OnAudioFocusChangeListener audioFocusChangeListener = new OnAudioFocusChangeListener()
{
public void onAudioFocusChange(int focusChange)
{
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT)
{
mp.setVolume(0.01f, 0.01f);
}
else if (focusChange == AudioManager.AUDIOFOCUS_GAIN)
{
mp.setVolume(1.0f, 1.0f);
}
else if (focusChange == AudioManager.AUDIOFOCUS_LOSS)
{
//stop playback and release everything---------------still need to confirm this is working
Play playService = new Play();
playService.stopPlaying();
//playService.stopAllServices();
//Intent stopPlayingService = new Intent("com.joebutt.mouseworldradio.Play");
//playService.getApplicationContext();
//Context context = (Context) OnAudioFocusChangeListener.this;
Intent stopPlayingService = new Intent(playService.getBaseContext(), Play.class);
//stopPlayingService.setAction(Intent.);
//stopService(stopPlayingService);
playService.stopService(stopPlayingService);
}
}
};