Should have subtitle controller already set Mediaplayer error Android

匿名 (未验证) 提交于 2019-12-03 01:12:01

问题:

Whenever I play a media, it shows a warning in DDMS Should have subtitle controller already set

MY CODE:

private void start() {     mediaPlayer.start();          mediaPlayer.setOnCompletionListener(new OnCompletionListener() {         @Override         public void onCompletion(MediaPlayer mp) {             mp.stop();             mp.release();         }     }); }

DDMS LOG

Should have subtitle controller already set

info/warning (2, 0)

When I searched on Google, not even a single topic related to it. How can I get rid of or disable this?

回答1:

A developer recently added subtitle support to VideoView.

When the MediaPlayer starts playing a music (or other source), it checks if there is a SubtitleController and shows this message if it's not set. It doesn't seem to care about if the source you want to play is a music or video. Not sure why he did that.

Short answer: Don't care about this "Exception".


Edit :

Still present in Lollipop,

If MediaPlayer is only used to play audio files and you really want to remove these errors in the logcat, the code bellow set an empty SubtitleController to the MediaPlayer.

It should not be used in production environment and may have some side effects.

static MediaPlayer getMediaPlayer(Context context){      MediaPlayer mediaplayer = new MediaPlayer();      if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {         return mediaplayer;     }      try {         Class cMediaTimeProvider = Class.forName( "android.media.MediaTimeProvider" );         Class cSubtitleController = Class.forName( "android.media.SubtitleController" );         Class iSubtitleControllerAnchor = Class.forName( "android.media.SubtitleController$Anchor" );         Class iSubtitleControllerListener = Class.forName( "android.media.SubtitleController$Listener" );          Constructor constructor = cSubtitleController.getConstructor(new Class[]{Context.class, cMediaTimeProvider, iSubtitleControllerListener});          Object subtitleInstance = constructor.newInstance(context, null, null);          Field f = cSubtitleController.getDeclaredField("mHandler");          f.setAccessible(true);         try {             f.set(subtitleInstance, new Handler());         }         catch (IllegalAccessException e) {return mediaplayer;}         finally {             f.setAccessible(false);         }          Method setsubtitleanchor = mediaplayer.getClass().getMethod("setSubtitleAnchor", cSubtitleController, iSubtitleControllerAnchor);          setsubtitleanchor.invoke(mediaplayer, subtitleInstance, null);         //Log.e("", "subtitle is setted :p");     } catch (Exception e) {}      return mediaplayer; }

This code is trying to do the following from the hidden API

SubtitleController sc = new SubtitleController(context, null, null); sc.mHandler = new Handler(); mediaplayer.setSubtitleAnchor(sc, null)


回答2:

To remove message on logcat, i add a subtitle to track. On windows, right click on track -> Property -> Details -> insert a text on subtitle. Done :)



回答3:

Ignore this exception. Media player works fine with this exception. I am getting this exception on Lollipop 5.1. My Phone was set at silent mode. And I thought my media player is not working. To remove phone from silent mode programatically

AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int ringerMode = audioManager.getRingerMode(); audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);  // start your media player // before closing media player, reset your ausio manager to original //ringer mode   audioManager.setRingerMode(  
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!