original link:http://stackoverflow.com/questions/20087804/ should-have-subtitle-controller-already-set-mediaplayer-error-android/20149754#20149754
1 StaticMediaPlayer Getmediaplayer (context context) {2 3MediaPlayer MediaPlayer =NewMediaPlayer ();4 5 if(Android.os.Build.VERSION.SDK_INT <Android.os.Build.VERSION_CODES. KITKAT) {6 returnMediaPlayer;7 }8 9 Try {Tenclass<?> Cmediatimeprovider = Class.forName ("Android.media.MediaTimeProvider" ); Oneclass<?> Csubtitlecontroller = Class.forName ("Android.media.SubtitleController" ); Aclass<?> Isubtitlecontrolleranchor = Class.forName ("Android.media.subtitlecontroller$anchor" ); -class<?> Isubtitlecontrollerlistener = Class.forName ("Android.media.subtitlecontroller$listener" ); - theConstructor Constructor = Csubtitlecontroller.getconstructor (NewClass[]{context.class, Cmediatimeprovider, Isubtitlecontrollerlistener}); - -Object subtitleinstance = constructor.newinstance (Context,NULL,NULL); - +Field f = Csubtitlecontroller.getdeclaredfield ("Mhandler"); - +F.setaccessible (true); A Try { atF.set (Subtitleinstance,NewHandler ()); - } - Catch(Illegalaccessexception e) {returnMediaPlayer;} - finally { -F.setaccessible (false); - } in -Method Setsubtitleanchor = Mediaplayer.getclass (). GetMethod ("Setsubtitleanchor", Csubtitlecontroller, isubtitlecontrolleranchor); to +Setsubtitleanchor.invoke (MediaPlayer, Subtitleinstance,NULL); - //log.e ("", "subtitle is setted:p"); the}Catch(Exception e) {} * $ returnMediaPlayer;Panax Notoginseng}
This code was trying to does the following from the hidden API
1 New NULL NULL ); 2 New Handler (); 3 null)
E/mediaplayer:should has subtitle controller already set