微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 手机设计讨论 > MTK手机平台交流 > mt6735 如何让设置的通知音只播放前10秒

mt6735 如何让设置的通知音只播放前10秒

时间:10-02 整理:3721RD 点击:
[DESCRIPTION]
当通知音设置为SD卡的音乐时,当通知音响起时,会放完整首歌,时间较长,如何只让它播放前10秒?
[SOLUTION]
修改方式如下:
请在NotificationManagerService.java里按照如下修改:
1. 引入相关文件
import java.util.Timer;
import java.util.TimerTask;

2. 增加定义
private Timer musicTimer;
private boolean mPlayTimer = false;
private final static long MUSIC_LENTH = 1000 * 30; // 30 second

3. 在enqueueNotificationInternal函数中修改如下,注意add modify 标注
if ((audioManager.getStreamVolume(audioStreamType) != 0)
&& !audioManager.isAudioFocusExclusive()) {
final long identity = Binder.clearCallingIdentity();
try {
final IRingtonePlayer player = mAudioService.getRingtonePlayer();
if (player != null) {
///M: [ALPS00461691] Override user because AudioService won't play sound for USER_ALL
if (user.getIdentifier() == UserHandle.USER_ALL) {
player.playAsync(soundUri, UserHandle.OWNER, looping, audioStreamType);
} else {
player.playAsync(soundUri, user, looping, audioStreamType);
}
//add modify
if(mPlayTimer == true){
musicTimer.cancel();
musicTimer = null;
mPlayTimer = false;
}
Slog.d(TAG, "enqueueNotificationInternal: musicTimer = new Timer()");
musicTimer = new Timer();
musicTimer.schedule(new TimerTask() {
@Override
public void run() {
final long identity2 = Binder.clearCallingIdentity();
try {
final IRingtonePlayer player2 = mAudioService.getRingtonePlayer();
if (player2 != null) {
Slog.d(TAG, "enqueueNotificationInternal: player.stopAsync");
player2.stopAsync();
}
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(identity2);
}
if (DBG) {
Slog.d(TAG, "enqueueNotificationInternal: stop music because arived timer:" + MUSIC_LENTH);
}
}
}, MUSIC_LENTH);
mPlayTimer = true;
//end modify
}
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(identity);
}
}
}
编译后会生成services.jar。

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

网站地图

Top