Browse Source

VLCPlaybackController: remove currentlyPlayingMediaFile that returns MLFile and replace it with VLCMedia to be available on both platforms

Carola Nitz 7 years ago
parent
commit
a70b6ace13

+ 1 - 2
Apple-TV/Playback/Playback Info/VLCPlaybackInfoMediaInfoTVViewController.m

@@ -49,8 +49,7 @@
     VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
     VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
     self.titleLabel.text = vpc.metadata.title;
     self.titleLabel.text = vpc.metadata.title;
 
 
-    VLCMediaPlayer *player = vpc.mediaPlayer;
-    VLCMedia *media = player.media;
+    VLCMedia *media = [vpc currentlyPlayingMedia];
 
 
     NSArray *mediaTrackData = media.tracksInformation;
     NSArray *mediaTrackData = media.tracksInformation;
     NSUInteger trackDataCount = mediaTrackData.count;
     NSUInteger trackDataCount = mediaTrackData.count;

+ 19 - 19
Sources/VLCPlaybackController+MediaLibrary.m

@@ -45,27 +45,27 @@ Open a file in the libraryViewController without changing the playstate
 
 
 - (void)openMediaLibraryObject:(NSManagedObject *)mediaObject
 - (void)openMediaLibraryObject:(NSManagedObject *)mediaObject
 {
 {
-    if (self.isPlaying) {
-        NSArray *files = [MLFile fileForURL:self.mediaPlayer.media.url];
-        MLFile *nowPlayingFile = (MLFile *)(NSManagedObject *)files.firstObject;
-        MLFile *newFile;
-        if ([mediaObject isKindOfClass:[MLAlbumTrack class]]) {
-            newFile = ((MLAlbumTrack *)mediaObject).anyFileFromTrack;
-        } else if ([mediaObject isKindOfClass:[MLShowEpisode class]]) {
-            newFile = ((MLShowEpisode *)mediaObject).anyFileFromEpisode;
-        } else if ([mediaObject isKindOfClass:[MLFile class]]) {
-            newFile = (MLFile *)mediaObject;
-        }
-
-        //if the newfile is not the currently playing one, stop and start the new one else do nothing
-        if (![nowPlayingFile isEqual:newFile]) {
-            [self stopPlayback];
-            [self playMediaLibraryObject:mediaObject];
-        }
+    if (!self.isPlaying) {
+        //if nothing is playing start playing
+        [self playMediaLibraryObject:mediaObject];
         return;
         return;
     }
     }
-    //if nothing is playing start playing
-    [self playMediaLibraryObject:mediaObject];
+    MLFile *newFile;
+    if ([mediaObject isKindOfClass:[MLAlbumTrack class]]) {
+        newFile = ((MLAlbumTrack *)mediaObject).anyFileFromTrack;
+    } else if ([mediaObject isKindOfClass:[MLShowEpisode class]]) {
+        newFile = ((MLShowEpisode *)mediaObject).anyFileFromEpisode;
+    } else if ([mediaObject isKindOfClass:[MLFile class]]) {
+        newFile = (MLFile *)mediaObject;
+    }
+
+    //if the newfile is not the currently playing one, stop and start the new one else do nothing
+    VLCMedia *currentlyPlayingFile = self.currentlyPlayingMedia;
+    MLFile *currentMLFile = [MLFile fileForURL:currentlyPlayingFile.url].firstObject;
+    if (![currentMLFile isEqual:newFile]) {
+        [self stopPlayback];
+        [self playMediaLibraryObject:mediaObject];
+    }
 }
 }
 
 
 - (void)configureWithFile:(MLFile *)file
 - (void)configureWithFile:(MLFile *)file

+ 3 - 4
Sources/VLCPlaybackController.h

@@ -50,10 +50,9 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
 
 
 @property (nonatomic, retain) VLCMediaList *mediaList;
 @property (nonatomic, retain) VLCMediaList *mediaList;
 
 
-#if TARGET_OS_IOS
-/* returns nil if currently playing item is not a MLFile, e.g. a url */
-@property (nonatomic, strong, readonly) MLFile *currentlyPlayingMediaFile;
-#endif
+/* returns nil if currently playing item is not available,*/
+
+@property (nonatomic, strong, readonly) VLCMedia *currentlyPlayingMedia;
 
 
 @property (nonatomic, weak) id<VLCPlaybackControllerDelegate> delegate;
 @property (nonatomic, weak) id<VLCPlaybackControllerDelegate> delegate;
 
 

+ 8 - 10
Sources/VLCPlaybackController.m

@@ -47,6 +47,7 @@ AVAudioSessionDelegate,
 VLCMediaDelegate, VLCRemoteControlServiceDelegate>
 VLCMediaDelegate, VLCRemoteControlServiceDelegate>
 {
 {
     VLCRemoteControlService *_remoteControlService;
     VLCRemoteControlService *_remoteControlService;
+    VLCMediaPlayer *_mediaPlayer;
     BOOL _playerIsSetup;
     BOOL _playerIsSetup;
     BOOL _shouldResumePlaying;
     BOOL _shouldResumePlaying;
     BOOL _sessionWillRestart;
     BOOL _sessionWillRestart;
@@ -907,18 +908,16 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
 
 
 #pragma mark - Managing the media item
 #pragma mark - Managing the media item
 
 
-#if TARGET_OS_IOS
-- (MLFile *)currentlyPlayingMediaFile {
-    if (self.mediaList) {
-        NSArray *results = [MLFile fileForURL:_mediaPlayer.media.url];
-        return results.firstObject;
-    }
-
-    return nil;
+- (VLCMedia *)currentlyPlayingMedia
+{
+    return _mediaPlayer.media;
 }
 }
-#endif
 
 
 #pragma mark - metadata handling
 #pragma mark - metadata handling
+- (void)performNavigationAction:(VLCMediaPlaybackNavigationAction)action
+{
+    [_mediaPlayer performNavigationAction:action];
+}
 - (void)mediaDidFinishParsing:(VLCMedia *)aMedia
 - (void)mediaDidFinishParsing:(VLCMedia *)aMedia
 {
 {
     [self setNeedsMetadataUpdate];
     [self setNeedsMetadataUpdate];
@@ -1108,7 +1107,6 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
 {
 {
     self.playbackRate = playbackRate;
     self.playbackRate = playbackRate;
 }
 }
-
 #pragma mark - helpers
 #pragma mark - helpers
 
 
 - (NSDictionary *)mediaOptionsDictionary
 - (NSDictionary *)mediaOptionsDictionary

+ 3 - 2
Sources/VLCWatchCommunication.m

@@ -162,8 +162,9 @@ static VLCWatchCommunication *_singeltonInstance = nil;
     if (nowPlayingInfo) {
     if (nowPlayingInfo) {
         response[@"nowPlayingInfo"] = nowPlayingInfo;
         response[@"nowPlayingInfo"] = nowPlayingInfo;
     }
     }
-    MLFile *currentFile = [VLCPlaybackController sharedInstance].currentlyPlayingMediaFile;
-    NSString *URIString = currentFile.objectID.URIRepresentation.absoluteString;
+    VLCMedia *currentFile = [VLCPlaybackController sharedInstance].currentlyPlayingMedia;
+    MLFile *mediaFile = [MLFile fileForURL:currentFile.url].firstObject;
+    NSString *URIString = mediaFile.objectID.URIRepresentation.absoluteString;
     if (URIString) {
     if (URIString) {
         response[VLCWatchMessageKeyURIRepresentation] = URIString;
         response[VLCWatchMessageKeyURIRepresentation] = URIString;
     }
     }