123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- /*****************************************************************************
- * VLCPlaybackController+MediaLibrary.m
- * VLC for iOS
- *****************************************************************************
- * Copyright (c) 2015 VideoLAN. All rights reserved.
- * $Id$
- *
- * Authors: Tobias Conradi <videolan # tobias-conradi.de>
- *
- * Refer to the COPYING file of the official project for license.
- *****************************************************************************/
- #import "VLCPlaybackController+MediaLibrary.h"
- #import <CoreData/CoreData.h>
- @implementation VLCPlaybackController (MediaLibrary)
- /*
- Open a file in the libraryViewController and toggle the playstate
- @param mediaObject the object that should be openend
-
- */
- - (void)playMediaLibraryObject:(NSManagedObject *)mediaObject
- {
- self.fullscreenSessionRequested = YES;
- if ([mediaObject isKindOfClass:[MLFile class]]) {
- [self configureWithFile:(MLFile *)mediaObject];
- }
- else if ([mediaObject isKindOfClass:[MLAlbumTrack class]]) {
- [self configureWithAlbumTrack:(MLAlbumTrack *)mediaObject];
- self.fullscreenSessionRequested = NO;
- }
- else if ([mediaObject isKindOfClass:[MLShowEpisode class]])
- [self configureWithShowEpisode:(MLShowEpisode *)mediaObject];
- }
- /*
- Open a file in the libraryViewController without changing the playstate
- @param mediaObject the object that should be openend
- */
- - (void)openMediaLibraryObject:(NSManagedObject *)mediaObject
- {
- if (!self.isPlaying) {
- //if nothing is playing start playing
- [self playMediaLibraryObject:mediaObject];
- return;
- }
- 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
- {
- if (file.labels.count == 0) {
- [self configureMediaListWithFiles:@[file] indexToPlay:0];
- } else {
- MLLabel *folder = [file.labels anyObject];
- NSArray *files = [folder sortedFolderItems];
- int index = (int)[files indexOfObject:file];
- [self configureMediaListWithFiles:files indexToPlay:index];
- }
- }
- - (void)configureWithShowEpisode:(MLShowEpisode *)showEpisode
- {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- if (![defaults boolForKey:kVLCAutomaticallyPlayNextItem]) {
- [self playMediaLibraryObject:showEpisode.files.anyObject];
- return;
- }
- NSArray *episodes = [[showEpisode show] sortedEpisodes];
- NSMutableArray *files = [NSMutableArray arrayWithCapacity:episodes.count];
- for (MLShowEpisode *episode in episodes) {
- MLFile *file = episode.files.anyObject;
- if (file)
- [files addObject:file];
- }
- int index = (int)[episodes indexOfObject:showEpisode];
- [self configureMediaListWithFiles:files indexToPlay:index];
- }
- - (void)configureWithAlbumTrack:(MLAlbumTrack *)albumTrack
- {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- if (![defaults boolForKey:kVLCAutomaticallyPlayNextItem]) {
- [self playMediaLibraryObject:albumTrack.anyFileFromTrack];
- return;
- }
- NSArray *tracks = [[albumTrack album] sortedTracks];
- NSMutableArray *files = [NSMutableArray arrayWithCapacity:tracks.count];
- for (MLAlbumTrack *track in tracks) {
- MLFile *file = track.anyFileFromTrack;
- if (file)
- [files addObject:file];
- }
- int index = (int)[tracks indexOfObject:albumTrack];
- [self configureMediaListWithFiles:files indexToPlay:index];
- }
- - (void)configureMediaListWithFiles:(NSArray *)files indexToPlay:(int)index
- {
- VLCMediaList *list = [[VLCMediaList alloc] init];
- VLCMedia *media;
- for (MLFile *file in files.reverseObjectEnumerator) {
- media = [VLCMedia mediaWithURL:file.url];
- [media addOptions:self.mediaOptionsDictionary];
- [list addMedia:media];
- }
- [self configureMediaList:list atIndex:index];
- }
- - (void)configureMediaList:(VLCMediaList *)list atIndex:(int)index
- {
- [self playMediaList:list firstIndex:index subtitlesFilePath:nil];
- }
- @end
|