VLCPlaybackController+MediaLibrary.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*****************************************************************************
  2. * VLCPlaybackController+MediaLibrary.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015-2019 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Carola Nitz <caro #videolan.org>
  9. * Tobias Conradi <videolan # tobias-conradi.de>
  10. *
  11. * Refer to the COPYING file of the official project for license.
  12. *****************************************************************************/
  13. #import "VLCPlaybackController+MediaLibrary.h"
  14. #import <VLCMediaLibraryKit/VLCMLFile.h>
  15. #import <VLCMediaLibraryKit/VLCMLMedia.h>
  16. @implementation VLCPlaybackController (MediaLibrary)
  17. - (void)playMediaAtIndex:(NSInteger)index fromCollection:(NSArray<VLCMLMedia *> *)collection
  18. {
  19. [self configureMediaListWithMLMedia:collection indexToPlay:(int) index];
  20. }
  21. - (void)playMedia:(VLCMLMedia *)media
  22. {
  23. [self configureMediaListWithMLMedia:@[media] indexToPlay:0];
  24. }
  25. - (void)configureMediaListWithMLMedia:(NSArray<VLCMLMedia *> *)mlMedia indexToPlay:(int)index {
  26. NSAssert(index >= 0, @"The index should never be negative");
  27. VLCMediaList *list = [[VLCMediaList alloc] init];
  28. VLCMedia *media;
  29. for (VLCMLMedia *file in mlMedia) {
  30. media = [VLCMedia mediaWithURL: file.mainFile.mrl];
  31. [media addOptions:self.mediaOptionsDictionary];
  32. [list addMedia:media];
  33. }
  34. [self configureMediaList:list atIndex:index];
  35. }
  36. - (void)configureMediaList:(VLCMediaList *)list atIndex:(int)index
  37. {
  38. [self playMediaList:list firstIndex:index subtitlesFilePath:nil];
  39. }
  40. @end