Carica una risorsa creando direttamente un’istanza di MediaResource e caricando il contenuto video da riprodurre. Questo è uno dei modi per caricare una risorsa multimediale.
Imposta l'elemento riproducibile del lettore multimediale con la nuova risorsa da riprodurre.
Sostituisci l'elemento attualmente riproducibile del lettore multimediale esistente chiamando MediaPlayer.replaceCurrentItem
e il passaggio di un MediaResource
dell'istanza.
Registra un'implementazione di MediaPlayer.PlaybackEventListener
interfaccia con MediaPlayer
dell'istanza.
onPrepared
onStateChanged
, e verificare se sono stati impostati i valori INITIALIZED ed ERROR.Quando lo stato del lettore multimediale diventa INITIALIZED, è possibile chiamare MediaPlayer.prepareToPlay
Lo stato INIZIALIZZATO indica che il supporto è stato caricato correttamente. Chiamata prepareToPlay
avvia il processo di risoluzione e posizionamento pubblicitario, se presente.
Quando TVSDK chiama onPrepared
callback, il flusso multimediale è stato caricato correttamente ed è pronto per la riproduzione.
Quando il flusso multimediale viene caricato, MediaPlayerItem
viene creato.
Se si verifica un errore, il
MediaPlayer
passa allo stato ERROR. Notifica inoltre l'applicazione chiamando ilPlaybackEventListener.onStateChanged
callback.In questo modo vengono trasmessi diversi parametri:
A
state
parametro di tipoMediaPlayer.PlayerState
con il valore diMediaPlayer.PlayerState.ERROR
.A
notification
parametro di tipoMediaPlayerNotification
che contiene informazioni di diagnostica sull’evento di errore.
Il seguente codice di esempio semplificato illustra il processo di caricamento di una risorsa multimediale:
// mediaResource is a properly configured MediaResource instance
// mediaPlayer is a MediaPlayer instance
// register a PlaybackEventListener implementation with the MediaPlayer
instancemediaPlayer.addEventListener(
MediaPlayer.Event.PLAYBACK,
new MediaPlayer.PlaybackEventListener()) {
@Overridepublic void onPrepared() {
// at this point, the resource is successfully loaded and available
// and the MediaPlayer is ready to start the playback
// once the resource is loaded, the MediaPlayer is able to
// provide a reference to the current "playable item"
MediaPlayerItem playerItem = mediaPlayer.CurrentItem();
if (playerItem != null) {
// here we can take a look at the properties of the
// loaded stream
}
} @Overridepublic void onStateChanged(
MediaPlayer.PlayerState state,
MediaPlayerNotification notification) {
if (state == MediaPlayer.PlayerState.ERROR) {
// something bad happened - the resource cannot be loaded
// details about the problem are provided via the
// MediaPlayerNotification instance
}
elseif (state == MediaPlayer.PlayerState.INITIALIZED) {
mediaPlayer.prepareToPlay();
}
}
// implementation of the other methods in the PlaybackEventListener interface...
}