138

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?

Community
  • 1
  • 1
Sai
  • 15,188
  • 20
  • 81
  • 121

3 Answers3

188

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)
Hacketo
  • 4,978
  • 4
  • 19
  • 34
  • 12
    I agree - it's not an error if a subtitle track doesn't exist. Informational at most. – Someone Somewhere Dec 19 '13 at 20:40
  • 4
    ok, sure, but is there an easy way to suppress it? it's junking up my logcat output... – TJ Ellis Aug 22 '14 at 18:05
  • Can make a filter i think if it's really annoying, recompile android, or setting an empty SubtitleController for your song. – Hacketo Aug 22 '14 at 18:28
  • 1
    @Hacketo how do you set an empty SubtitleController? Sorry I don't see this in the docs. – Frank Schwieterman Sep 15 '14 at 22:54
  • 2
    Of course the documentation is not providing this information. If you've seen the code shared of the MediaPlayer you can see that there is a setter for the SubtitleController (so it should be possible), but unfortunately seem unavailable. – Hacketo Sep 16 '14 at 07:30
9

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 :)

StefanoM5
  • 1,327
  • 1
  • 24
  • 34
  • 1
    Couple thoughts on this: 1) modifying source file isn't really feasible in a lot of situations. 2) you didn't explain why adding a subtitle track would fix an error on a subtitle controller in the MediaPlayer. – Travis Castillo Jun 25 '17 at 05:45
  • The error is "Should have subtitle controller already set", so i add a subtitle to track so avoid this error message. – StefanoM5 Jun 26 '17 at 07:28
  • subtitle or subtitle controller. are you saying that by having a subtitle track on a video the media player automatically generates a controller? – Travis Castillo Jul 18 '17 at 16:18
0

Also you can only set mediaPlayer.reset() and in onDestroy set it to release.

Faizan Haidar Khan
  • 1,099
  • 1
  • 15
  • 20