我们从MediaPlayer的start方法开始:
//frameworks/base/media/java/android/media/MediaPlayer.java
public class MediaPlayer extends PlayerBase implements SubtitleController.Listener, VolumeAutomation, AudioRouting {
public void start() throws IllegalStateException {
//FIXME use lambda to pass startImpl to superclass
final int delay = getStartDelayMs();
if (delay == 0) { //如果delay时间为0,直接调用startImpl方法
startImpl();
} else { //如果delay不为了,创建一个线程,然后让线程sleep,sleep的时间为delay,然后再调用startImpl方法
new Thread() {
public void run() {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
e.printStackTrace();
}
baseSetStartDelayMs(0);
try {
startImpl();
} catch (IllegalStateException e) {
// fail silently for a state exception when it is happening after
// a delayed start, as the player state could have changed between the
// call to start() and the execution of startImpl()
}
}
}.start();
}
}
}
调用startImpl方法:
//frameworks/base/media/java/android/media/MediaPlayer.java
public class MediaPlayer extends PlayerBase implements SubtitleController.Listener, VolumeAutomation, AudioRouting {
private void startImpl() {
baseStart(0); // unknown device at this point
stayAwake(true); //保持唤醒状态
tryToEnableNativeRoutingCallback();
_start();
}
}
上面方法主要处理如下:
调用baseStart方法,也就是父类PlayerBase的baseStart方法。
调用stayAwake方法,保持电源唤醒状态。
调用_start方

3636

被折叠的 条评论
为什么被折叠?



