E/MediaPlayer: Should have subtitle controller already set

 

原文链接:http://stackoverflow.com/questions/20087804/should-have-subtitle-controller-already-set-mediaplayer-error-android/20149754#20149754

 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)