Commit 52dbbe90 authored by Carola's avatar Carola Committed by Felix Paul Kühne
Browse files

playlistViewController: added VLCMedialistDelegate



note: we should wait for the addMedia callback before playing lists
Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent 46cf0a7d
...@@ -43,7 +43,7 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria ...@@ -43,7 +43,7 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
@end @end
@interface VLCPlaylistViewController () <VLCFolderCollectionViewDelegateFlowLayout, LXReorderableCollectionViewDataSource, LXReorderableCollectionViewDelegateFlowLayout, UITableViewDataSource, UITableViewDelegate, MLMediaLibrary> { @interface VLCPlaylistViewController () <VLCFolderCollectionViewDelegateFlowLayout, LXReorderableCollectionViewDataSource, LXReorderableCollectionViewDelegateFlowLayout, UITableViewDataSource, UITableViewDelegate, MLMediaLibrary, VLCMediaListDelegate> {
NSMutableArray *_foundMedia; NSMutableArray *_foundMedia;
VLCLibraryMode _libraryMode; VLCLibraryMode _libraryMode;
VLCLibraryMode _previousLibraryMode; VLCLibraryMode _previousLibraryMode;
...@@ -54,6 +54,9 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria ...@@ -54,6 +54,9 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
LXReorderableCollectionViewFlowLayout *_reorderLayout; LXReorderableCollectionViewFlowLayout *_reorderLayout;
BOOL inFolder; BOOL inFolder;
UILongPressGestureRecognizer *_longPressGestureRecognizer; UILongPressGestureRecognizer *_longPressGestureRecognizer;
NSInteger _mediaToPlayIndex;
VLCMediaList *_list;
NSArray *_tracks;
} }
@property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) UITableView *tableView;
...@@ -520,37 +523,44 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria ...@@ -520,37 +523,44 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
[tableView deselectRowAtIndexPath:indexPath animated:YES]; [tableView deselectRowAtIndexPath:indexPath animated:YES];
NSManagedObject *selectedObject = _foundMedia[indexPath.row]; NSManagedObject *selectedObject = _foundMedia[indexPath.row];
if ([selectedObject isKindOfClass:[MLAlbumTrack class]]) { if ([selectedObject isKindOfClass:[MLAlbumTrack class]]) {
VLCMediaList *list; _tracks = [[(MLAlbumTrack*)selectedObject album] sortedTracks];
NSArray *tracks = [[(MLAlbumTrack*)selectedObject album] sortedTracks]; NSUInteger count = _tracks.count;
NSUInteger count = tracks.count; _list = [[VLCMediaList alloc] init];
list = [[VLCMediaList alloc] init]; _list.delegate = self;
MLFile *file; MLFile *file;
VLCMedia *media; VLCMedia *media;
for (NSInteger x = count - 1; x > -1; x--) { for (NSInteger x = count - 1; x > -1; x--) {
file = [(MLAlbumTrack*)tracks[x] files].anyObject; file = [(MLAlbumTrack*)_tracks[x] files].anyObject;
media = [VLCMedia mediaWithURL: [NSURL URLWithString:file.url]]; media = [VLCMedia mediaWithURL: [NSURL URLWithString:file.url]];
[media parse]; [media parse];
[list addMedia:media]; [_list addMedia:media];
} }
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate openMediaList:list atIndex:(int)[tracks indexOfObject:selectedObject]]; _mediaToPlayIndex = indexPath.row;
} else if ([selectedObject isKindOfClass:[MLFile class]] && [((MLFile *)selectedObject).labels count] > 0) { } else if ([selectedObject isKindOfClass:[MLFile class]] && [((MLFile *)selectedObject).labels count] > 0) {
VLCMediaList *list;
MLLabel *folder = [((MLFile *)selectedObject).labels anyObject]; MLLabel *folder = [((MLFile *)selectedObject).labels anyObject];
NSArray *folderTracks = [folder sortedFolderItems]; _tracks = [folder sortedFolderItems];
NSUInteger count = folderTracks.count; NSUInteger count = _tracks.count;
list = [[VLCMediaList alloc] init]; _list = [[VLCMediaList alloc] init];
_list.delegate = self;
MLFile *file; MLFile *file;
for (NSInteger x = count - 1; x > -1; x--) { for (NSInteger x = count - 1; x > -1; x--) {
file = (MLFile *)folderTracks[x]; file = (MLFile *)_tracks[x];
[list addMedia:[VLCMedia mediaWithURL:[NSURL URLWithString:file.url]]]; [_list addMedia:[VLCMedia mediaWithURL:[NSURL URLWithString:file.url]]];
} }
[(VLCAppDelegate *)[UIApplication sharedApplication].delegate openMediaList:list atIndex:(int)[folderTracks indexOfObject:selectedObject]]; _mediaToPlayIndex = indexPath.row;
} else } else
[self openMediaObject:selectedObject]; [self openMediaObject:selectedObject];
} }
#pragma mark - VLCMedialistDelegate
- (void)mediaList:(VLCMediaList *)aMediaList mediaAdded:(VLCMedia *)media atIndex:(NSInteger)index
{
if (index == _tracks.count - 1) {
NSManagedObject *selectedObject = _foundMedia[_mediaToPlayIndex];
[(VLCAppDelegate *)[UIApplication sharedApplication].delegate openMediaList:_list atIndex:(int)[_tracks indexOfObject:selectedObject]];
}
}
#pragma mark - table view gestures #pragma mark - table view gestures
- (void)swipeRightGestureAction:(UIGestureRecognizer *)recognizer - (void)swipeRightGestureAction:(UIGestureRecognizer *)recognizer
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment