MediaPlayer : Should have subtitle controller already set: KitKat

android, android-4.4-kitkat, android-mediaplayer

Solution

Looking at a previous discussion on StackOverflow, and the referenced Android commit where this was introduced, the code above might not completely initialize the `MediaPlayer` object.

The KitKat example code for media playback suggests that you should call:

mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

immediately after you construct the `MediaPlayer`, and before you call its `setDataSource` method.

Problem

I am having an odd issue where my audio file sometimes plays and sometimes does not play. The catch is that when it decides to not play, the DDMS gives me an: ``` E/MediaPlayer﹕ Should have subtitle controller already set ``` Because this is one-to-one with the music not playing, I have determined that this is probably the issue... If the music is not playing and I hit the volume button it begins to play. If I wait about 30 seconds of no-play, it begins to start again (not looping). Whats going on here? I am on KitKat using ``` player = new MediaPlayer(); AssetFileDescriptor afd = null; try { afd = getAssets().openFd("Theme.mp3"); } catch (IOException e) { e.printStackTrace(); } try { player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); } catch (IOException e) { e.printStackTrace(); } try { player.prepare(); } catch (IOException e) { e.printStackTrace(); } player.setLooping(true); //restart playback end reached //player.setVolume(1, 1); //Set left and right volumes. Range is from 0.0 to 1.0 player.start(); //start play back ```

Original source

Related problems