Explorar o código

Media List Player: adapt to libvlc 3.0 API

Felix Paul Kühne %!s(int64=9) %!d(string=hai) anos
pai
achega
45d4010fbb
Modificáronse 3 ficheiros con 33 adicións e 9 borrados
  1. 1 0
      Headers/Public/VLCMediaPlayer.h
  2. 11 7
      Sources/VLCMediaListPlayer.m
  3. 21 2
      Sources/VLCMediaPlayer.m

+ 1 - 0
Headers/Public/VLCMediaPlayer.h

@@ -101,6 +101,7 @@ extern NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state);
 - (instancetype)initWithVideoLayer:(VLCVideoLayer *)aVideoLayer;
 #endif
 - (instancetype)initWithOptions:(NSArray *)options;
+- (instancetype)initWithLibVLCInstance:(void *)playerInstance andLibrary:(VLCLibrary *)library;
 
 /* Video View Options */
 // TODO: Should be it's own object?

+ 11 - 7
Sources/VLCMediaListPlayer.m

@@ -29,6 +29,7 @@
 #import "VLCMediaPlayer.h"
 #import "VLCMediaList.h"
 #import "VLCLibVLCBridging.h"
+#import "VLCLibrary.h"
 
 @interface VLCMediaListPlayer () {
     void *instance;
@@ -43,14 +44,17 @@
 
 - (instancetype)initWithOptions:(NSArray *)options
 {
-        if (self = [super init]) {
-            _mediaPlayer = [[VLCMediaPlayer alloc] initWithOptions:options];
-
-            instance = libvlc_media_list_player_new([_mediaPlayer.libraryInstance instance]);
-            libvlc_media_list_player_set_media_player(instance, [_mediaPlayer libVLCMediaPlayer]);
-        }
-        return self;
+    if (self = [super init]) {
+        VLCLibrary *library;
+        if (options != nil) {
+            library = [[VLCLibrary alloc] initWithOptions:options];
+        } else
+            library = [VLCLibrary sharedLibrary];
 
+        instance = libvlc_media_list_player_new([library instance]);
+        _mediaPlayer = [[VLCMediaPlayer alloc] initWithLibVLCInstance:libvlc_media_list_player_get_media_player(instance) andLibrary:library];
+    }
+    return self;
 }
 
 - (instancetype)init

+ 21 - 2
Sources/VLCMediaPlayer.m

@@ -147,7 +147,7 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
 // TODO: Documentation
 @interface VLCMediaPlayer (Private)
 
-- (id)initWithDrawable:(id)aDrawable options:(NSArray *)options;
+- (instancetype)initWithDrawable:(id)aDrawable options:(NSArray *)options;
 
 - (void)registerObservers;
 - (void)unregisterObservers;
@@ -203,6 +203,25 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
     return [self initWithDrawable:nil options:nil];
 }
 
+- (instancetype)initWithLibVLCInstance:(void *)playerInstance andLibrary:(VLCLibrary *)library
+{
+    if (self = [super init]) {
+        _cachedTime = [VLCTime nullTime];
+        _cachedRemainingTime = [VLCTime nullTime];
+        _position = 0.0f;
+        _cachedState = VLCMediaPlayerStateStopped;
+
+        _privateLibrary = library;
+        libvlc_retain([_privateLibrary instance]);
+
+        _playerInstance = playerInstance;
+        libvlc_media_player_retain(_playerInstance);
+
+        [self registerObservers];
+    }
+    return self;
+}
+
 #if !TARGET_OS_IPHONE
 - (instancetype)initWithVideoView:(VLCVideoView *)aVideoView
 {
@@ -1155,7 +1174,7 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
 @end
 
 @implementation VLCMediaPlayer (Private)
-- (id)initWithDrawable:(id)aDrawable options:(NSArray *)options
+- (instancetype)initWithDrawable:(id)aDrawable options:(NSArray *)options
 {
     if (self = [super init]) {
         _cachedTime = [VLCTime nullTime];