burakk
burakk

Reputation: 1291

Videos of the Sample App Not Running in the Android TV Emulator

The videos in the sample app (AndroidTV Leanback Support Library sample for videos - https://github.com/googlesamples/androidtv-Leanback) do not play in the Android TV emulator. I'm running the app on an Android_TV_1080p_API_21 emulator. What could be wrong?


Edit: I'm getting the following log output:

2247-2260/com.example.android.tvleanback E/MediaPlayer﹕ error (1, -38)
2247-2247/com.example.android.tvleanback E/MediaPlayer﹕ Error (1,-38)
2247-2247/com.example.android.tvleanback E/MediaPlayer﹕ stop called in state 0
2247-2247/com.example.android.tvleanback E/MediaPlayer﹕ error (-38, 0)
2247-2247/com.example.android.tvleanback W/MediaPlayer﹕ mediaplayer went away with unhandled events

Upvotes: 1

Views: 1773

Answers (1)

Ashok Varma
Ashok Varma

Reputation: 3539

Method:1 You need to call mediaPlayer.start() in the onPrepared method by using a listener "OnPreparedListener()". You are getting this error because you are calling mediaPlayer.start() before it has reached the prepared state.

Here is how you can do it :

mp.setDataSource(url); 
mp.setOnPreparedListener(this);
mp.prepareAsync();

public void onPrepared(MediaPlayer player) {
    player.start();
}

Method 2: It seems like Error -38 means a state-exception (as the error-message indicates). For example if you call start(), before the song was ready, or when you call pause(), even if the song isn't playing at all.

To fix this issue check the state of the mediaPlayer before calling the methods. For example:

if(mediaPlayer.isPlaying()) {
    mediaPlayer.pause();
}

Additionally, the MediaPlayer is sending event-messages. Even if you do not need the prepared-event (although it would be a good idea to not start the playback before this event was fired) you must set a callback-listener. This also holds true for the OnErrorListener, OnCompletionListener, OnPreparedListener and OnSeekCompletedListener (if you call the seek method).

Listeners can be attached simply by

mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        // Do something. For example: playButton.setEnabled(true);
    }
}); 

Source Link:-Media Player called in state 0, error (-38,0)

Upvotes: 1

Related Questions