E/MediaPlayer: Should have subtitle controller already set
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了E/MediaPlayer: Should have subtitle controller already set相关的知识,希望对你有一定的参考价值。
1 static MediaPlayer getMediaPlayer(Context context){
2
3 MediaPlayer mediaplayer = new MediaPlayer();
4
5 if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
6 return mediaplayer;
7 }
8
9 try {
10 Class<?> cMediaTimeProvider = Class.forName( "android.media.MediaTimeProvider" );
11 Class<?> cSubtitleController = Class.forName( "android.media.SubtitleController" );
12 Class<?> iSubtitleControllerAnchor = Class.forName( "android.media.SubtitleController$Anchor" );
13 Class<?> iSubtitleControllerListener = Class.forName( "android.media.SubtitleController$Listener" );
14
15 Constructor constructor = cSubtitleController.getConstructor(new Class[]{Context.class, cMediaTimeProvider, iSubtitleControllerListener});
16
17 Object subtitleInstance = constructor.newInstance(context, null, null);
18
19 Field f = cSubtitleController.getDeclaredField("mHandler");
20
21 f.setAccessible(true);
22 try {
23 f.set(subtitleInstance, new Handler());
24 }
25 catch (IllegalAccessException e) {return mediaplayer;}
26 finally {
27 f.setAccessible(false);
28 }
29
30 Method setsubtitleanchor = mediaplayer.getClass().getMethod("setSubtitleAnchor", cSubtitleController, iSubtitleControllerAnchor);
31
32 setsubtitleanchor.invoke(mediaplayer, subtitleInstance, null);
33 //Log.e("", "subtitle is setted :p");
34 } catch (Exception e) {}
35
36 return mediaplayer;
37 }
This code is trying to do the following from the hidden API
1 SubtitleController sc = new SubtitleController(context, null, null);
2 sc.mHandler = new Handler();
3 mediaplayer.setSubtitleAnchor(sc, null)
以上是关于E/MediaPlayer: Should have subtitle controller already set的主要内容,如果未能解决你的问题,请参考以下文章
E/MediaPlayer: start called in state 4, mPlayer(0xcc719a40)解决
MediaPlayer:应该已经设置了字幕控制器:KitKat