Browse Source

VLCMediaPlayer: expand the API to switch / disable video tracks in similar fashion to SPU and Audio

Felix Paul Kühne 12 years ago
parent
commit
168999a157
2 changed files with 55 additions and 2 deletions
  1. 18 1
      Headers/Public/VLCMediaPlayer.h
  2. 37 1
      Sources/VLCMediaPlayer.m

+ 18 - 1
Headers/Public/VLCMediaPlayer.h

@@ -3,7 +3,7 @@
  *****************************************************************************
  * Copyright (C) 2007-2009 Pierre d'Herbemont
  * Copyright (C) 2007-2009 VLC authors and VideoLAN
- * Partial Copyright (C) 2009 Felix Paul Kühne
+ * Copyright (C) 2009-2013 Felix Paul Kühne
  * $Id$
  *
  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
@@ -167,6 +167,23 @@ extern NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state);
 @property (readonly) NSUInteger fps;
 
 /**
+ * Return the current video track index
+ * Note that the handled values do not match the videoTracks array indexes
+ * but refer to VLCMedia's VLCMediaTracksInformationId.
+ * \return 0 if none is set.
+ *
+ * Pass 0 to disable.
+ */
+@property (readwrite) NSUInteger currentVideoTrackIndex;
+
+/**
+ * Return the video tracks
+ *
+ * It includes the disabled fake track at index 0.
+ */
+- (NSArray *)videoTracks;
+
+/**
  * Return the current video subtitle index
  * Note that the handled values do not match the videoSubTitles array indexes
  * but refer to VLCMedia's VLCMediaTracksInformationId.

+ 37 - 1
Sources/VLCMediaPlayer.m

@@ -272,6 +272,42 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
 }
 
 #pragma mark -
+#pragma mark Video Tracks
+- (void)setCurrentVideoTrackIndex:(NSUInteger)value
+{
+    libvlc_video_set_track(instance, (int)value);
+}
+
+- (NSUInteger)currentVideoTrackIndex
+{
+    NSInteger count = libvlc_video_get_track_count(instance);
+    if (count <= 0)
+        return NSNotFound;
+
+    NSUInteger result = libvlc_video_get_track(instance);
+    return result;
+}
+
+- (NSArray *)videoTracks
+{
+    NSInteger count = libvlc_video_get_track_count(instance);
+    if (count <= 0)
+        return [NSArray array];
+
+    libvlc_track_description_t *tracks = libvlc_video_get_track_description(instance);
+    NSMutableArray *tempArray = [NSMutableArray array];
+    NSUInteger i;
+    for (i = 0; i < count ; i++)
+    {
+        [tempArray addObject:[NSString stringWithUTF8String: tracks->psz_name]];
+        tracks = tracks->p_next;
+    }
+    libvlc_track_description_release(tracks);
+
+    return [NSArray arrayWithArray: tempArray];
+}
+
+#pragma mark -
 #pragma mark Subtitles
 
 - (void)setCurrentVideoSubTitleIndex:(NSUInteger)index
@@ -481,7 +517,7 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
 #pragma mark Audio tracks
 - (void)setCurrentAudioTrackIndex:(NSUInteger)value
 {
-    libvlc_audio_set_track( instance, (int)value);
+    libvlc_audio_set_track(instance, (int)value);
 }
 
 - (NSUInteger)currentAudioTrackIndex