代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void addEffect(String effectPath) {
if (effectPlayer == null) {
effectPlayer = new MediaPlayer();
} else {
effectPlayer.stop(); //问题出在这里,stop 进入 stopped 状态,需要再调用 reset 才能进入 Idle 状态
}
try {
effectPlayer.setDataSource(effectPath);
twoVideoLayer.setDisplayTexture2(true);
effectPlayer.setSurface(new Surface(twoVideoLayer.getVideoTexture2()));
effectPlayer.prepare();
effectPlayer.start();
} catch (Exception e) {
Log.e(TAG, "播放特效失败", e);
}
}
异常信息1
2
3
4
5
6
7
8
9java.lang.IllegalStateException
at android.media.MediaPlayer._setDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1154)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1139)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1118)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1067)
at com.lansosdk.videoeditor.LansoPlayer.addEffect(LansoPlayer.java:88)
at work.wangxiang.lansodemo.PlayerActivity.onEffect(PlayerActivity.java:50)
at java.lang.reflect.Method.invoke(Native Method)
Idle 状态下,才可调用 setDataSource 方法。
调用 reset,才会进入 Idle 状态。