Selaa lähdekoodia

media player: add new notifications for title and chapter change

(cherry picked from commit 5654db3f64492b8a9926ab221f256b8b64ea4d05)
Felix Paul Kühne 9 vuotta sitten
vanhempi
commit
aeb1ac51e6
3 muutettua tiedostoa jossa 47 lisäystä ja 0 poistoa
  1. 17 0
      Headers/Public/VLCMediaPlayer.h
  2. 1 0
      NEWS
  3. 29 0
      Sources/VLCMediaPlayer.m

+ 17 - 0
Headers/Public/VLCMediaPlayer.h

@@ -42,6 +42,8 @@
 /* Notification Messages */
 extern NSString *const VLCMediaPlayerTimeChanged;
 extern NSString *const VLCMediaPlayerStateChanged;
+extern NSString *const VLCMediaPlayerTitleChanged;
+extern NSString *const VLCMediaPlayerChapterChanged;
 
 /**
  * VLCMediaPlayerState describes the state of the media player.
@@ -85,6 +87,21 @@ extern NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state);
  */
 - (void)mediaPlayerTimeChanged:(NSNotification *)aNotification;
 
+/**
+ * Sent by the default notification center whenever the player's title has changed (if any).
+ * \details Discussion The value of aNotification is always an VLCMediaPlayerTitleChanged notification. You can retrieve
+ * the VLCMediaPlayer object in question by sending object to aNotification.
+ * \note this is about a title in the navigation sense, not about metadata
+ */
+- (void)mediaPlayerTitleChanged:(NSNotification *)aNotification;
+
+/**
+ * Sent by the default notification center whenever the player's chapter has changed (if any).
+ * \details Discussion The value of aNotification is always an VLCMediaPlayerChapterChanged notification. You can retrieve
+ * the VLCMediaPlayer object in question by sending object to aNotification.
+ */
+- (void)mediaPlayerChapterChanged:(NSNotification *)aNotification;
+
 #if TARGET_OS_PHONE
 /**
  * Sent by the default notification center whenever a new snapshot is taken.

+ 1 - 0
NEWS

@@ -14,6 +14,7 @@ New APIs:
                       snapshots, lastSnapshot
   - added selectors: chaptersForTitleIndex:
                      numberOfChaptersForTitle:
+  - added notifications: VLCMediaPlayerTitleChanged, VLCMediaPlayerChapterChanged
 
 - VLCMedia
   - added keys: VLCMetaInformationTrackTotal, VLCMetaInformationDirector,

+ 29 - 0
Sources/VLCMediaPlayer.m

@@ -50,6 +50,8 @@
 /* Notification Messages */
 NSString *const VLCMediaPlayerTimeChanged       = @"VLCMediaPlayerTimeChanged";
 NSString *const VLCMediaPlayerStateChanged      = @"VLCMediaPlayerStateChanged";
+NSString *const VLCMediaPlayerTitleChanged       = @"VLCMediaPlayerTitleChanged";
+NSString *const VLCMediaPlayerChapterChanged      = @"VLCMediaPlayerChapterChanged";
 NSString *const VLCMediaPlayerSnapshotTaken     = @"VLCMediaPlayerSnapshotTaken";
 
 /* title keys */
@@ -144,6 +146,24 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
     }
 }
 
+static void HandleMediaTitleChanged(const libvlc_event_t * event, void * self)
+{
+    @autoreleasepool {
+        [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:(__bridge id)(self)
+                                                       withDelegateMethod:@selector(mediaPlayerTimeChanged:)
+                                                     withNotificationName:VLCMediaPlayerTitleChanged];
+    }
+}
+
+static void HandleMediaChapterChanged(const libvlc_event_t * event, void * self)
+{
+    @autoreleasepool {
+        [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:(__bridge id)(self)
+                                                       withDelegateMethod:@selector(mediaPlayerChapterChanged:)
+                                                     withNotificationName:VLCMediaPlayerChapterChanged];
+    }
+}
+
 #if TARGET_OS_IPHONE
 static void HandleMediaPlayerSnapshot(const libvlc_event_t * event, void * self)
 {
@@ -172,6 +192,9 @@ static void HandleMediaPlayerSnapshot(const libvlc_event_t * event, void * self)
 - (void)mediaPlayerPositionChanged:(NSNumber *)newTime;
 - (void)mediaPlayerStateChanged:(NSNumber *)newState;
 - (void)mediaPlayerMediaChanged:(VLCMedia *)media;
+- (void)mediaPlayerTitleChanged:(NSNumber *)newTitle;
+- (void)mediaPlayerChapterChanged:(NSNumber *)newChapter;
+
 #if TARGET_OS_IPHONE
 - (void)mediaPlayerSnapshot:(NSString *)fileName;
 #endif
@@ -1262,6 +1285,9 @@ static void HandleMediaPlayerSnapshot(const libvlc_event_t * event, void * self)
     libvlc_event_attach(p_em, libvlc_MediaPlayerTimeChanged,      HandleMediaTimeChanged,          (__bridge void *)(self));
     libvlc_event_attach(p_em, libvlc_MediaPlayerMediaChanged,     HandleMediaPlayerMediaChanged,   (__bridge void *)(self));
 
+    libvlc_event_attach(p_em, libvlc_MediaPlayerTitleChanged,     HandleMediaTitleChanged,         (__bridge void *)(self));
+    libvlc_event_attach(p_em, libvlc_MediaPlayerChapterChanged,   HandleMediaChapterChanged,       (__bridge void *)(self));
+
 #if TARGET_OS_IPHONE
     libvlc_event_attach(p_em, libvlc_MediaPlayerSnapshotTaken,    HandleMediaPlayerSnapshot,       (__bridge void *)(self));
 #endif
@@ -1285,6 +1311,9 @@ static void HandleMediaPlayerSnapshot(const libvlc_event_t * event, void * self)
     libvlc_event_detach(p_em, libvlc_MediaPlayerTimeChanged,      HandleMediaTimeChanged,          (__bridge void *)(self));
     libvlc_event_detach(p_em, libvlc_MediaPlayerMediaChanged,     HandleMediaPlayerMediaChanged,   (__bridge void *)(self));
 
+    libvlc_event_detach(p_em, libvlc_MediaPlayerTitleChanged,     HandleMediaTitleChanged,         (__bridge void *)(self));
+    libvlc_event_detach(p_em, libvlc_MediaPlayerChapterChanged,   HandleMediaChapterChanged,       (__bridge void *)(self));
+
 #if TARGET_OS_IPHONE
     libvlc_event_detach(p_em, libvlc_MediaPlayerSnapshotTaken,    HandleMediaPlayerSnapshot,       (__bridge void *)(self));
 #endif