微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 手机设计讨论 > MTK手机平台交流 > mt6735 Music播放后恢复FM后台播放

mt6735 Music播放后恢复FM后台播放

时间:10-02 整理:3721RD 点击:
[DESCRIPTION]
1. 启动FM播放。
2. 播放music,此时FM被停止播放。等music播放一段时间后暂停,FM不会自动恢复播放。

[SOLUTION]
1. 改变申请audiofocus的类型。
在MediaPlaybackService.java
(alps\packages\apps\music\src\com\android\music)
public void play() 中去申请audio focus->AUDIOFOCUS_GAIN_TRANSIENT。即:
if (AudioManager.AUDIOFOCUS_REQUEST_FAILED ==
mAudioManager.requestAudioFocus(
mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.
AUDIOFOCUS_GAIN)) {
showToast(getString(R.string.audiofocus_request_failed_message));
MusicLogUtils.w(TAG, "<< play: phone call is ongoing, can not play
music!");
return;
}
改为:
if (AudioManager.AUDIOFOCUS_REQUEST_FAILED ==
mAudioManager.requestAudioFocus(
mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.
AUDIOFOCUS_GAIN_TRANSIENT)) {
showToast(getString(R.string.audiofocus_request_failed_message));
MusicLogUtils.w(TAG, "<< play: phone call is ongoing, can not play
music!");
return;
}

2. 暂停的时候去做audiofocus释放动作。
在public void pause() 的时候去释放audiofocus
在MusicLogUtils.d(TAG, "pause");之后添加如下两句:
// abandon audiofocus
// abandon audio focus
mAudioManager.abandonAudioFocus(mAudioFocusListener);

3. 在FM获取到audiofocus的时候做Resume动作。
在FMRadioService.java
(alps\mediatek\packages\apps\fmradio\src\com\mediatek\fmradio)
public void onAudioFocusChange(int focusChange) 中的如下case中,当获取到
audiofocus的时候做resume的动作。
case AudioManager.AUDIOFOCUS_GAIN:
LogUtils.d(TAG, "AudioFocus: received AUDIOFOCUS_GAIN");
updateAudioFocusAync(AudioManager.AUDIOFOCUS_GAIN);
//resume FM Player
resumeFMAudio();
break;

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top