El reproductor puede escuchar una serie de eventos que indican el estado del reproductor.
Suponiendo que PTMediaPlayer
es una propiedad del reproductor cliente, self.player
en el siguiente ejemplo representa el PTMediaPlayer
ejemplo. El siguiente ejemplo implementa las addObservers
que se muestran en las instrucciones de configuración de PTMediaPlayer e incluyen la mayoría de las notificaciones:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerStatusChange:)
name:PTMediaPlayerStatusNotification object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerNotification:)
name:PTMediaPlayerNewNotificationEntryAddedNotification object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerTimeChange:)
name:PTMediaPlayerTimeChangeNotification object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerItemPlayStarted:)
name:PTMediaPlayerPlayStartedNotification object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerItemPlayCompleted:)
name:PTMediaPlayerPlayCompletedNotification object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerItemTimelineChanged:)
name:PTMediaPlayerTimelineChangedNotification object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerItemMediaSelectionOptionsAvailable:)
name:PTMediaPlayerMediaSelectionOptionsAvailableNotification object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerAdBreakStarted:)
name:PTMediaPlayerAdBreakStartedNotification object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerAdBreakCompleted:)
name:PTMediaPlayerAdBreakCompletedNotification object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerAdPlayStarted:)
name:PTMediaPlayerAdStartedNotification object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerAdPlayProgress:)
name:PTMediaPlayerAdProgressNotification object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerAdPlayCompleted:)
name:PTMediaPlayerAdCompletedNotification object:self.player];
ThePTMediaPlayerNotifications
enumera las notificaciones que el TVSDK envía al reproductor.
Notificación | Significado |
PTMediaPlayerAdBreakCompletedNotification | Ha finalizado una pausa publicitaria. |
PTMediaPlayerAdBreakStartedNotification | Se inició una pausa publicitaria. |
PTMediaPlayerAdClickNotification | Un usuario hizo clic en un anuncio de banner. |
PTMediaPlayerAdCompletedNotification | Finalizó un anuncio individual. |
PTMediaPlayerAdProgressNotification | Un anuncio ha progresado; se envía constantemente mientras se reproduce otro. |
PTMediaPlayerAdStartedNotification | Se inició un anuncio individual. |
PTBackgroundManifestErrorNotification | Error al descargar el manifiesto de fondo. |
PTMediaPlayerBufferingCompletedNotification | Se completó el almacenamiento en búfer. |
PTMediaPlayerBufferingStartedNotification | El reproductor multimedia entra en estado de almacenamiento en búfer. |
PTAudioTrackChangeCompleted | Se ha completado un cambio en la pista de audio de los medios que se están reproduciendo. |
PTAudioTrackChangeStarted | Se inicia un cambio en la pista de audio de los medios que se están reproduciendo. |
PTMediaPlayerItemChangedNotification | Un elemento diferente PTMediaPlayerItem de la PTMediaPlayer se ha establecido. |
PTMediaPlayerItemDRMMetadataChanged | Metadatos de DRM cambiados. |
PTMediaPlayerMediaSelectionOptionsAvailableNotification | Hay nuevos subtítulos y pistas de audio alternativas ( PTMediaSelectionOption ). |
PTMediaPlayerNewNotificationEntryAddedNotification | Un nuevo PTNotification se ha añadido a PTNotificationHistoryItem del actual PTMediaPlayerItem , es decir, cuando se añade un evento de notificación al historial de notificaciones. |
PTMediaPlayerPlayCompletedNotification | Finalizó la reproducción de contenido. |
PTMediaPlayerSeekCompletedNotification | La búsqueda se ha completado. |
PTMediaPlayerSeekErrorNotification | Error en la operación de búsqueda actual. |
PTMediaPlayerSeekStartedNotification | La búsqueda está empezando. |
PTMediaPlayerPlayStartedNotification | Reproducción iniciada. |
PTMediaPlayerStatusNotification | El estado del reproductor ha cambiado. Los posibles valores de estado son:
|
PTMediaPlayerTimeChangeNotification | El tiempo actual de reproducción ha cambiado. |
PTMediaPlayerTimelineChangedNotification | La cronología del reproductor actual ha cambiado. |
PTTimedMetadataChangedNotification | TVSDK encontró la primera aparición de una etiqueta suscrita. |
PTTimedMetadataChangedInBackgroundNotification | Una etiqueta suscrita se identifica en el manifiesto de fondo y una nueva PTTimedMetadata La instancia de se prepara a partir de ella. |
Los siguientes fragmentos de código ilustran algunas de las formas de utilizar las notificaciones.
Recupere el PTAdBreak
instancia con PTMediaPlayerAdBreakKey
:
- (void) onMediaPlayerAdBreakStarted:(NSNotification *) notification {
// Fetch the PTAdBreak instance using PTMediaPlayerAdBreakKey
PTAdBreak *adBreak = [notification.userInfo objectForKey:PTMediaPlayerAdBreakKey];
...
...
}
Establecer subtitlesOptions
y audioOptions
:
- (void) onMediaPlayerItemMediaSelectionOptionsAvailable:(NSNotification \*) notification {
//SubtitlesOptions and audioOptions are set and accessible now.
NSArray* subtitlesOptions = self.player.currentItem.subtitlesOptions;
NSArray* audioOp tions = self.player.currentItem.audioOptions;
...
...
}
Recupere el PTAd
instancia con PTMediaPlayerAdKey
:
- (void) onMediaPlayerAdPlayStarted:(NSNotification \*) notification {
// Fetch the PTAdinstance using PTMediaPlayerAdKey
PTAd *ad = [notification.userInfo objectForKey:PTMediaPlayerAdKey];
...
...
}