Il lettore può ascoltare una serie di eventi che indicano lo stato del lettore.
Supponendo che PTMediaPlayer
sia una proprietà del lettore client, self.player
nell'esempio seguente rappresenta l'istanza PTMediaPlayer
. L'esempio seguente implementa il metodo addObservers
mostrato nelle istruzioni di configurazione di PTMediaPlayer e include la maggior parte delle notifiche:
[[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
in questa classe sono elencate le notifiche inviate dal TVSDK al lettore.
Notifica | Significato |
PTMediaPlayerAdBreakCompletedNotification | Una pausa pubblicitaria è finita. |
PTMediaPlayerAdBreakStartedNotification | È iniziata una pausa pubblicitaria. |
PTMediaPlayerAdClickNotification | Un utente ha fatto clic su un banner pubblicitario. |
PTMediaPlayerAdCompletedNotification | Un singolo annuncio è terminato. |
PTMediaPlayerAdProgressNotification | Un annuncio progredito; inviato costantemente mentre un annuncio suona. |
PTMediaPlayerAdStartedNotification | Un annuncio individuale è iniziato. |
PTBackgroundManifestErrorNotification | Download del manifesto di sfondo non riuscito. |
PTMediaPlayerBufferingCompletedNotification | Buffering completato. |
PTMediaPlayerBufferingStartedNotification | Il lettore multimediale entra in uno stato di buffering. |
PTAudioTrackChangeCompleted | È stata completata una modifica alla traccia audio del file multimediale attualmente in riproduzione. |
PTAudioTrackChangeStarted | Viene avviata una modifica sulla traccia audio del file multimediale attualmente in riproduzione. |
PTMediaPlayerItemChangedNotification | È stato impostato un PTMediaPlayerItem diverso di PTMediaPlayer . |
PTMediaPlayerItemDRMMetadataChanged | Metadati DRM modificati. |
PTMediaPlayerMediaSelectionOptionsAvailableNotification | Sono disponibili nuovi sottotitoli e tracce audio alternative ( PTMediaSelectionOption ). |
PTMediaPlayerNewNotificationEntryAddedNotification | È stata aggiunta una nuova notifica PTN al PTNotificationHistoryItem dell'elemento PTMediaPlayerItem corrente, ovvero quando viene aggiunto un evento di notifica alla cronologia delle notifiche. |
PTMediaPlayerPlayCompletedNotification | Riproduzione file multimediali terminata. |
PTMediaPlayerSeekCompletedNotification | Ricerca completata. |
PTMediaPlayerSeekErrorNotification | L'operazione di ricerca corrente non è riuscita. |
PTMediaPlayerSeekStartedNotification | La ricerca sta iniziando. |
PTMediaPlayerPlayStartedNotification | Riproduzione avviata. |
PTMediaPlayerStatusNotification | Lo stato del lettore è cambiato. I valori di stato possibili sono:
|
PTMediaPlayerTimeChangeNotification | L'ora corrente di riproduzione è cambiata. |
PTMediaPlayerTimelineChangedNotification | La timeline del lettore corrente è cambiata. |
PTTimedMetadataChangedNotification | TVSDK ha rilevato la prima occorrenza di un tag di sottoscrizione. |
PTTimedMetadataChangedInBackgroundNotification | Un tag di sottoscrizione viene identificato sul manifesto di background e ne viene preparata una nuova istanza PTTimedMetadata . |
I frammenti di codice seguenti illustrano alcuni dei modi in cui è possibile utilizzare le notifiche.
Recupera l'istanza PTAdBreak
utilizzando PTMediaPlayerAdBreakKey
:
- (void) onMediaPlayerAdBreakStarted:(NSNotification *) notification {
// Fetch the PTAdBreak instance using PTMediaPlayerAdBreakKey
PTAdBreak *adBreak = [notification.userInfo objectForKey:PTMediaPlayerAdBreakKey];
...
...
}
Imposta subtitlesOptions
e 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;
...
...
}
Recupera l'istanza PTAd
utilizzando PTMediaPlayerAdKey
:
- (void) onMediaPlayerAdPlayStarted:(NSNotification \*) notification {
// Fetch the PTAdinstance using PTMediaPlayerAdKey
PTAd *ad = [notification.userInfo objectForKey:PTMediaPlayerAdKey];
...
...
}