VLCPlaybackController.m 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  1. /*****************************************************************************
  2. * VLCPlaybackController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Carola Nitz <caro # videolan.org>
  10. * Gleb Pinigin <gpinigin # gmail.com>
  11. * Pierre Sagaspe <pierre.sagaspe # me.com>
  12. * Tobias Conradi <videolan # tobias-conradi.de>
  13. * Sylver Bruneau <sylver.bruneau # gmail dot com>
  14. * Winston Weinert <winston # ml1 dot net>
  15. *
  16. * Refer to the COPYING file of the official project for license.
  17. *****************************************************************************/
  18. #import "VLCPlaybackController.h"
  19. #import "UIDevice+VLC.h"
  20. #import <AVFoundation/AVFoundation.h>
  21. #import "VLCPlayerDisplayController.h"
  22. #import "VLCConstants.h"
  23. #import "VLCRemoteControlService.h"
  24. #import "VLCMetadata.h"
  25. NSString *const VLCPlaybackControllerPlaybackDidStart = @"VLCPlaybackControllerPlaybackDidStart";
  26. NSString *const VLCPlaybackControllerPlaybackDidPause = @"VLCPlaybackControllerPlaybackDidPause";
  27. NSString *const VLCPlaybackControllerPlaybackDidResume = @"VLCPlaybackControllerPlaybackDidResume";
  28. NSString *const VLCPlaybackControllerPlaybackDidStop = @"VLCPlaybackControllerPlaybackDidStop";
  29. NSString *const VLCPlaybackControllerPlaybackMetadataDidChange = @"VLCPlaybackControllerPlaybackMetadataDidChange";
  30. NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPlaybackDidFail";
  31. NSString *const VLCPlaybackControllerPlaybackPositionUpdated = @"VLCPlaybackControllerPlaybackPositionUpdated";
  32. typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
  33. VLCAspectRatioDefault = 0,
  34. VLCAspectRatioFillToScreen,
  35. VLCAspectRatioFourToThree,
  36. VLCAspectRatioSixteenToNine,
  37. VLCAspectRatioSixteenToTen,
  38. };
  39. @interface VLCPlaybackController () <VLCMediaPlayerDelegate,
  40. #if TARGET_OS_IOS
  41. AVAudioSessionDelegate,
  42. #endif
  43. VLCMediaDelegate, VLCRemoteControlServiceDelegate>
  44. {
  45. VLCRemoteControlService *_remoteControlService;
  46. BOOL _playerIsSetup;
  47. BOOL _shouldResumePlaying;
  48. BOOL _sessionWillRestart;
  49. BOOL _shouldResumePlayingAfterInteruption;
  50. NSString *_pathToExternalSubtitlesFile;
  51. int _itemInMediaListToBePlayedFirst;
  52. NSTimer *_sleepTimer;
  53. NSUInteger _currentAspectRatio;
  54. UIView *_videoOutputViewWrapper;
  55. UIView *_actualVideoOutputView;
  56. UIView *_preBackgroundWrapperView;
  57. BOOL _needsMetadataUpdate;
  58. BOOL _mediaWasJustStarted;
  59. BOOL _recheckForExistingThumbnail;
  60. BOOL _headphonesWasPlugged;
  61. NSLock *_playbackSessionManagementLock;
  62. VLCDialogProvider *_dialogProvider;
  63. NSMutableArray *_shuffleStack;
  64. }
  65. @end
  66. @implementation VLCPlaybackController
  67. #pragma mark instance management
  68. + (VLCPlaybackController *)sharedInstance
  69. {
  70. static VLCPlaybackController *sharedInstance = nil;
  71. static dispatch_once_t pred;
  72. dispatch_once(&pred, ^{
  73. sharedInstance = [VLCPlaybackController new];
  74. });
  75. return sharedInstance;
  76. }
  77. - (void)dealloc
  78. {
  79. _dialogProvider = nil;
  80. [[NSNotificationCenter defaultCenter] removeObserver:self];
  81. }
  82. - (instancetype)init
  83. {
  84. self = [super init];
  85. if (self) {
  86. // listen to audiosessions and appkit callback
  87. _headphonesWasPlugged = [self areHeadphonesPlugged];
  88. NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
  89. [defaultCenter addObserver:self selector:@selector(audioSessionRouteChange:)
  90. name:AVAudioSessionRouteChangeNotification object:nil];
  91. // appkit because we neeed to know when we go to background in order to stop the video, so that we don't crash
  92. [defaultCenter addObserver:self selector:@selector(applicationWillResignActive:)
  93. name:UIApplicationWillResignActiveNotification object:nil];
  94. [defaultCenter addObserver:self selector:@selector(applicationDidBecomeActive:)
  95. name:UIApplicationDidBecomeActiveNotification object:nil];
  96. [defaultCenter addObserver:self selector:@selector(applicationDidEnterBackground:)
  97. name:UIApplicationDidEnterBackgroundNotification object:nil];
  98. _metadata = [VLCMetaData new];
  99. _dialogProvider = [[VLCDialogProvider alloc] initWithLibrary:[VLCLibrary sharedLibrary] customUI:NO];
  100. _playbackSessionManagementLock = [[NSLock alloc] init];
  101. _shuffleMode = NO;
  102. _shuffleStack = [[NSMutableArray alloc] init];
  103. }
  104. return self;
  105. }
  106. - (VLCRemoteControlService *)remoteControlService
  107. {
  108. if (!_remoteControlService) {
  109. _remoteControlService = [[VLCRemoteControlService alloc] init];
  110. _remoteControlService.remoteControlServiceDelegate = self;
  111. }
  112. return _remoteControlService;
  113. }
  114. #pragma mark - playback management
  115. - (void)playMediaList:(VLCMediaList *)mediaList firstIndex:(NSInteger)index subtitlesFilePath:(NSString *)subsFilePath
  116. {
  117. self.mediaList = mediaList;
  118. _itemInMediaListToBePlayedFirst = (int)index;
  119. _pathToExternalSubtitlesFile = subsFilePath;
  120. _sessionWillRestart = self.isPlaying;
  121. self.isPlaying ? [self stopPlayback] : [self startPlayback];
  122. }
  123. - (void)startPlayback
  124. {
  125. if (_playerIsSetup) {
  126. APLog(@"%s: player is already setup, bailing out", __PRETTY_FUNCTION__);
  127. return;
  128. }
  129. BOOL ret = [_playbackSessionManagementLock tryLock];
  130. if (!ret) {
  131. APLog(@"%s: locking failed", __PRETTY_FUNCTION__);
  132. return;
  133. }
  134. #if TARGET_OS_IOS
  135. [[AVAudioSession sharedInstance] setDelegate:self];
  136. #endif
  137. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  138. if (!self.mediaList) {
  139. APLog(@"%s: no URL and no media list set, stopping playback", __PRETTY_FUNCTION__);
  140. [_playbackSessionManagementLock unlock];
  141. [self stopPlayback];
  142. return;
  143. }
  144. /* video decoding permanently fails if we don't provide a UIView to draw into on init
  145. * hence we provide one which is not attached to any view controller for off-screen drawing
  146. * and disable video decoding once playback started */
  147. _actualVideoOutputView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  148. _actualVideoOutputView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  149. _actualVideoOutputView.autoresizesSubviews = YES;
  150. if (_pathToExternalSubtitlesFile)
  151. _listPlayer = [[VLCMediaListPlayer alloc] initWithOptions:@[[NSString stringWithFormat:@"--%@=%@", kVLCSettingSubtitlesFilePath, _pathToExternalSubtitlesFile]] andDrawable:_actualVideoOutputView];
  152. else
  153. _listPlayer = [[VLCMediaListPlayer alloc] initWithDrawable:_actualVideoOutputView];
  154. /* to enable debug logging for the playback library instance, switch the boolean below
  155. * note that the library instance used for playback may not necessarily match the instance
  156. * used for media discovery or thumbnailing */
  157. _listPlayer.mediaPlayer.libraryInstance.debugLogging = NO;
  158. _mediaPlayer = _listPlayer.mediaPlayer;
  159. [_mediaPlayer setDelegate:self];
  160. if ([[defaults objectForKey:kVLCSettingPlaybackSpeedDefaultValue] floatValue] != 0)
  161. [_mediaPlayer setRate: [[defaults objectForKey:kVLCSettingPlaybackSpeedDefaultValue] floatValue]];
  162. if ([[defaults objectForKey:kVLCSettingDeinterlace] intValue] != 0)
  163. [_mediaPlayer setDeinterlaceFilter:@"blend"];
  164. else
  165. [_mediaPlayer setDeinterlaceFilter:nil];
  166. if (_pathToExternalSubtitlesFile)
  167. [_mediaPlayer addPlaybackSlave:[NSURL fileURLWithPath:_pathToExternalSubtitlesFile] type:VLCMediaPlaybackSlaveTypeSubtitle enforce:YES];
  168. VLCMedia *media = [_mediaList mediaAtIndex:_itemInMediaListToBePlayedFirst];
  169. [media parseWithOptions:VLCMediaParseLocal];
  170. media.delegate = self;
  171. [media addOptions:self.mediaOptionsDictionary];
  172. [_listPlayer setMediaList:self.mediaList];
  173. [_listPlayer setRepeatMode:VLCDoNotRepeat];
  174. [_playbackSessionManagementLock unlock];
  175. [self _playNewMedia];
  176. }
  177. - (void)_playNewMedia
  178. {
  179. BOOL ret = [_playbackSessionManagementLock tryLock];
  180. if (!ret) {
  181. APLog(@"%s: locking failed", __PRETTY_FUNCTION__);
  182. return;
  183. }
  184. // Set last selected equalizer profile
  185. unsigned int profile = (unsigned int)[[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingEqualizerProfile] integerValue];
  186. [_mediaPlayer resetEqualizerFromProfile:profile];
  187. [_mediaPlayer setPreAmplification:[_mediaPlayer preAmplification]];
  188. _mediaWasJustStarted = YES;
  189. [_mediaPlayer addObserver:self forKeyPath:@"time" options:0 context:nil];
  190. [_mediaPlayer addObserver:self forKeyPath:@"remainingTime" options:0 context:nil];
  191. [_listPlayer playItemAtNumber:@(_itemInMediaListToBePlayedFirst)];
  192. if ([self.delegate respondsToSelector:@selector(prepareForMediaPlayback:)])
  193. [self.delegate prepareForMediaPlayback:self];
  194. _currentAspectRatio = VLCAspectRatioDefault;
  195. _mediaPlayer.videoAspectRatio = NULL;
  196. _mediaPlayer.scaleFactor = 0;
  197. [[self remoteControlService] subscribeToRemoteCommands];
  198. _playerIsSetup = YES;
  199. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidStart object:self];
  200. [_playbackSessionManagementLock unlock];
  201. }
  202. - (void)stopPlayback
  203. {
  204. BOOL ret = [_playbackSessionManagementLock tryLock];
  205. if (!ret) {
  206. APLog(@"%s: locking failed", __PRETTY_FUNCTION__);
  207. return;
  208. }
  209. if (_mediaPlayer) {
  210. @try {
  211. [_mediaPlayer removeObserver:self forKeyPath:@"time"];
  212. [_mediaPlayer removeObserver:self forKeyPath:@"remainingTime"];
  213. }
  214. @catch (NSException *exception) {
  215. APLog(@"we weren't an observer yet");
  216. }
  217. if (_mediaPlayer.media) {
  218. [_mediaPlayer pause];
  219. #if TARGET_OS_IOS
  220. [self _savePlaybackState];
  221. #endif
  222. [_mediaPlayer stop];
  223. }
  224. _mediaPlayer = nil;
  225. _listPlayer = nil;
  226. }
  227. if (!_sessionWillRestart) {
  228. _mediaList = nil;
  229. if (_pathToExternalSubtitlesFile) {
  230. NSFileManager *fileManager = [NSFileManager defaultManager];
  231. if ([fileManager fileExistsAtPath:_pathToExternalSubtitlesFile])
  232. [fileManager removeItemAtPath:_pathToExternalSubtitlesFile error:nil];
  233. _pathToExternalSubtitlesFile = nil;
  234. }
  235. }
  236. _playerIsSetup = NO;
  237. [_shuffleStack removeAllObjects];
  238. if (_errorCallback && _mediaPlayer.state == VLCMediaPlayerStateError && !_sessionWillRestart)
  239. [[UIApplication sharedApplication] openURL:_errorCallback];
  240. else if (_successCallback && !_sessionWillRestart)
  241. [[UIApplication sharedApplication] openURL:_successCallback];
  242. [[self remoteControlService] unsubscribeFromRemoteCommands];
  243. [_playbackSessionManagementLock unlock];
  244. if (!_sessionWillRestart) {
  245. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidStop object:self];
  246. } else {
  247. _sessionWillRestart = NO;
  248. [self startPlayback];
  249. }
  250. }
  251. #if TARGET_OS_IOS
  252. - (void)_savePlaybackState
  253. {
  254. @try {
  255. [[MLMediaLibrary sharedMediaLibrary] save];
  256. }
  257. @catch (NSException *exception) {
  258. APLog(@"saving playback state failed");
  259. }
  260. NSArray *files = [MLFile fileForURL:_mediaPlayer.media.url];
  261. MLFile *fileItem = files.firstObject;
  262. if (!fileItem) {
  263. APLog(@"couldn't find file, not saving playback progress");
  264. return;
  265. }
  266. @try {
  267. float position = _mediaPlayer.position;
  268. fileItem.lastPosition = @(position);
  269. fileItem.lastAudioTrack = @(_mediaPlayer.currentAudioTrackIndex);
  270. fileItem.lastSubtitleTrack = @(_mediaPlayer.currentVideoSubTitleIndex);
  271. if (position > .95)
  272. return;
  273. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  274. NSString* newThumbnailPath = [searchPaths[0] stringByAppendingPathComponent:@"VideoSnapshots"];
  275. NSFileManager *fileManager = [NSFileManager defaultManager];
  276. if (![fileManager fileExistsAtPath:newThumbnailPath])
  277. [fileManager createDirectoryAtPath:newThumbnailPath withIntermediateDirectories:YES attributes:nil error:nil];
  278. newThumbnailPath = [newThumbnailPath stringByAppendingPathComponent:fileItem.objectID.URIRepresentation.lastPathComponent];
  279. [_mediaPlayer saveVideoSnapshotAt:newThumbnailPath withWidth:0 andHeight:0];
  280. _recheckForExistingThumbnail = YES;
  281. [self performSelector:@selector(_updateStoredThumbnailForFile:) withObject:fileItem afterDelay:.25];
  282. }
  283. @catch (NSException *exception) {
  284. APLog(@"failed to save current media state - file removed?");
  285. }
  286. }
  287. #endif
  288. #if TARGET_OS_IOS
  289. - (void)_updateStoredThumbnailForFile:(MLFile *)fileItem
  290. {
  291. NSFileManager *fileManager = [NSFileManager defaultManager];
  292. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  293. NSString* newThumbnailPath = [searchPaths[0] stringByAppendingPathComponent:@"VideoSnapshots"];
  294. newThumbnailPath = [newThumbnailPath stringByAppendingPathComponent:fileItem.objectID.URIRepresentation.lastPathComponent];
  295. if (![fileManager fileExistsAtPath:newThumbnailPath]) {
  296. if (_recheckForExistingThumbnail) {
  297. [self performSelector:@selector(_updateStoredThumbnailForFile:) withObject:fileItem afterDelay:1.];
  298. _recheckForExistingThumbnail = NO;
  299. } else
  300. return;
  301. }
  302. UIImage *newThumbnail = [UIImage imageWithContentsOfFile:newThumbnailPath];
  303. if (!newThumbnail) {
  304. if (_recheckForExistingThumbnail) {
  305. [self performSelector:@selector(_updateStoredThumbnailForFile:) withObject:fileItem afterDelay:1.];
  306. _recheckForExistingThumbnail = NO;
  307. } else
  308. return;
  309. }
  310. @try {
  311. [fileItem setComputedThumbnailScaledForDevice:newThumbnail];
  312. }
  313. @catch (NSException *exception) {
  314. APLog(@"updating thumbnail failed");
  315. }
  316. [fileManager removeItemAtPath:newThumbnailPath error:nil];
  317. }
  318. #endif
  319. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  320. {
  321. if (_mediaWasJustStarted) {
  322. _mediaWasJustStarted = NO;
  323. #if TARGET_OS_IOS
  324. if (self.mediaList) {
  325. NSArray *matches = [MLFile fileForURL:_mediaPlayer.media.url];
  326. MLFile *item = matches.firstObject;
  327. [self _recoverLastPlaybackStateOfItem:item];
  328. }
  329. #else
  330. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  331. BOOL bValue = [defaults boolForKey:kVLCSettingUseSPDIF];
  332. if (bValue) {
  333. _mediaPlayer.audio.passthrough = bValue;
  334. }
  335. #endif
  336. }
  337. if ([self.delegate respondsToSelector:@selector(playbackPositionUpdated:)])
  338. [self.delegate playbackPositionUpdated:self];
  339. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackPositionUpdated
  340. object:self];
  341. }
  342. - (NSInteger)mediaDuration
  343. {
  344. return _mediaPlayer.media.length.intValue;;
  345. }
  346. - (BOOL)isPlaying
  347. {
  348. return _mediaPlayer.isPlaying;
  349. }
  350. - (VLCRepeatMode)repeatMode
  351. {
  352. return _listPlayer.repeatMode;
  353. }
  354. - (void)setRepeatMode:(VLCRepeatMode)repeatMode
  355. {
  356. _listPlayer.repeatMode = repeatMode;
  357. }
  358. - (BOOL)currentMediaHasChapters
  359. {
  360. return [_mediaPlayer numberOfTitles] > 1 || [_mediaPlayer numberOfChaptersForTitle:_mediaPlayer.currentTitleIndex] > 1;
  361. }
  362. - (BOOL)currentMediaHasTrackToChooseFrom
  363. {
  364. return [[_mediaPlayer audioTrackIndexes] count] > 2 || [[_mediaPlayer videoSubTitlesIndexes] count] > 1;
  365. }
  366. - (NSNumber *)playbackTime
  367. {
  368. return _mediaPlayer.time.value;
  369. }
  370. - (float)playbackRate
  371. {
  372. return _mediaPlayer.rate;
  373. }
  374. - (void)setPlaybackRate:(float)playbackRate
  375. {
  376. [_mediaPlayer setRate:playbackRate];
  377. _metadata.playbackRate = @(_mediaPlayer.rate);
  378. }
  379. - (void)setAudioDelay:(float)audioDelay
  380. {
  381. _mediaPlayer.currentAudioPlaybackDelay = 1000000.*audioDelay;
  382. }
  383. - (float)audioDelay
  384. {
  385. return _mediaPlayer.currentAudioPlaybackDelay/1000000.;
  386. }
  387. -(void)setSubtitleDelay:(float)subtitleDeleay
  388. {
  389. _mediaPlayer.currentVideoSubTitleDelay = 1000000.*subtitleDeleay;
  390. }
  391. - (float)subtitleDelay
  392. {
  393. return _mediaPlayer.currentVideoSubTitleDelay/1000000.;
  394. }
  395. - (NSInteger)indexOfCurrentAudioTrack
  396. {
  397. return [_mediaPlayer.audioTrackIndexes indexOfObject:@(_mediaPlayer.currentAudioTrackIndex)];
  398. }
  399. - (NSInteger)indexOfCurrentSubtitleTrack
  400. {
  401. return [_mediaPlayer.videoSubTitlesIndexes indexOfObject:@(_mediaPlayer.currentVideoSubTitleIndex)];
  402. }
  403. - (NSInteger)indexOfCurrentChapter
  404. {
  405. return _mediaPlayer.currentChapterIndex;
  406. }
  407. - (NSInteger)indexOfCurrentTitle
  408. {
  409. return _mediaPlayer.currentTitleIndex;
  410. }
  411. - (NSInteger)numberOfAudioTracks
  412. {
  413. return _mediaPlayer.audioTrackIndexes.count;
  414. }
  415. - (NSInteger)numberOfVideoSubtitlesIndexes
  416. {
  417. return _mediaPlayer.videoSubTitlesIndexes.count;
  418. }
  419. - (NSInteger)numberOfTitles
  420. {
  421. return [_mediaPlayer numberOfTitles];
  422. }
  423. - (NSInteger)numberOfChaptersForCurrentTitle
  424. {
  425. return [_mediaPlayer numberOfChaptersForTitle:_mediaPlayer.currentTitleIndex];
  426. }
  427. - (NSString *)videoSubtitleNameAtIndex:(NSInteger)index
  428. {
  429. if (index >= 0 && index < _mediaPlayer.videoSubTitlesNames.count)
  430. return _mediaPlayer.videoSubTitlesNames[index];
  431. return nil;
  432. }
  433. - (NSString *)audioTrackNameAtIndex:(NSInteger)index
  434. {
  435. if (index >= 0 && index < _mediaPlayer.audioTrackNames.count)
  436. return _mediaPlayer.audioTrackNames[index];
  437. return nil;
  438. }
  439. - (NSDictionary *)titleDescriptionsDictAtIndex:(NSInteger)index
  440. {
  441. if (index >= 0 && index < _mediaPlayer.titleDescriptions.count)
  442. return _mediaPlayer.titleDescriptions[index];
  443. return nil;
  444. }
  445. - (NSDictionary *)chapterDescriptionsDictAtIndex:(NSInteger)index
  446. {
  447. NSArray *chapterDescriptions = [_mediaPlayer chapterDescriptionsOfTitle:_mediaPlayer.currentTitleIndex];
  448. if (index >= 0 && index < chapterDescriptions.count)
  449. return chapterDescriptions[index];
  450. return nil;
  451. }
  452. - (void)selectAudioTrackAtIndex:(NSInteger)index
  453. {
  454. if (index >= 0 && index < _mediaPlayer.audioTrackIndexes.count) {
  455. //we can cast this cause we won't have more than 2 million audiotracks
  456. _mediaPlayer.currentAudioTrackIndex = [_mediaPlayer.audioTrackIndexes[index] intValue];
  457. }
  458. }
  459. - (void)selectVideoSubtitleAtIndex:(NSInteger)index
  460. {
  461. if (index >= 0 && index < _mediaPlayer.videoSubTitlesIndexes.count) {
  462. _mediaPlayer.currentVideoSubTitleIndex = [_mediaPlayer.videoSubTitlesIndexes[index] intValue];
  463. }
  464. }
  465. - (void)selectTitleAtIndex:(NSInteger)index
  466. {
  467. if (index >= 0 && index < [_mediaPlayer numberOfTitles]) {
  468. //we can cast this cause we won't have more than 2 million titles
  469. _mediaPlayer.currentTitleIndex = (int)index;
  470. }
  471. }
  472. - (void)selectChapterAtIndex:(NSInteger)index
  473. {
  474. if (index >= 0 && index < [self numberOfChaptersForCurrentTitle]) {
  475. //we can cast this cause we won't have more than 2 million chapters
  476. _mediaPlayer.currentChapterIndex = (int)index;
  477. }
  478. }
  479. - (void)mediaPlayerStateChanged:(NSNotification *)aNotification
  480. {
  481. VLCMediaPlayerState currentState = _mediaPlayer.state;
  482. if (currentState == VLCMediaPlayerStateBuffering) {
  483. /* attach delegate */
  484. _mediaPlayer.media.delegate = self;
  485. /* on-the-fly values through hidden API */
  486. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  487. [_mediaPlayer performSelector:@selector(setTextRendererFont:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFont]];
  488. [_mediaPlayer performSelector:@selector(setTextRendererFontSize:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFontSize]];
  489. [_mediaPlayer performSelector:@selector(setTextRendererFontColor:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFontColor]];
  490. [_mediaPlayer performSelector:@selector(setTextRendererFontForceBold:) withObject:[defaults objectForKey:kVLCSettingSubtitlesBoldFont]];
  491. } else if (currentState == VLCMediaPlayerStateError) {
  492. APLog(@"Playback failed");
  493. dispatch_async(dispatch_get_main_queue(),^{
  494. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidFail object:self];
  495. });
  496. _sessionWillRestart = NO;
  497. [self stopPlayback];
  498. } else if (currentState == VLCMediaPlayerStateEnded || currentState == VLCMediaPlayerStateStopped) {
  499. [_listPlayer.mediaList lock];
  500. NSUInteger listCount = _listPlayer.mediaList.count;
  501. if ([_listPlayer.mediaList indexOfMedia:_mediaPlayer.media] == listCount - 1 && self.repeatMode == VLCDoNotRepeat) {
  502. [_listPlayer.mediaList unlock];
  503. _sessionWillRestart = NO;
  504. [self stopPlayback];
  505. return;
  506. } else if (listCount > 1) {
  507. [_listPlayer.mediaList unlock];
  508. [_listPlayer next];
  509. } else
  510. [_listPlayer.mediaList unlock];
  511. }
  512. if ([self.delegate respondsToSelector:@selector(mediaPlayerStateChanged:isPlaying:currentMediaHasTrackToChooseFrom:currentMediaHasChapters:forPlaybackController:)])
  513. [self.delegate mediaPlayerStateChanged:currentState
  514. isPlaying:_mediaPlayer.isPlaying
  515. currentMediaHasTrackToChooseFrom:self.currentMediaHasTrackToChooseFrom
  516. currentMediaHasChapters:self.currentMediaHasChapters
  517. forPlaybackController:self];
  518. [self setNeedsMetadataUpdate];
  519. }
  520. #pragma mark - playback controls
  521. - (void)playPause
  522. {
  523. if ([_mediaPlayer isPlaying]) {
  524. [_listPlayer pause];
  525. #if TARGET_OS_IOS
  526. [self _savePlaybackState];
  527. #endif
  528. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidPause object:self];
  529. } else {
  530. [_listPlayer play];
  531. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidResume object:self];
  532. }
  533. }
  534. - (void)next
  535. {
  536. NSInteger mediaListCount = _mediaList.count;
  537. #if TARGET_OS_IOS
  538. if (mediaListCount > 2 && _shuffleMode) {
  539. NSNumber *nextIndex;
  540. NSUInteger currentIndex = [_mediaList indexOfMedia:_listPlayer.mediaPlayer.media];
  541. //Reached end of playlist
  542. if (_shuffleStack.count + 1 == mediaListCount) {
  543. if ([self repeatMode] == VLCDoNotRepeat)
  544. return;
  545. [_shuffleStack removeAllObjects];
  546. }
  547. [_shuffleStack addObject:[NSNumber numberWithUnsignedInteger:currentIndex]];
  548. do {
  549. nextIndex = [NSNumber numberWithUnsignedInt:arc4random_uniform((uint32_t)mediaListCount)];
  550. } while (currentIndex == nextIndex.unsignedIntegerValue || [_shuffleStack containsObject:nextIndex]);
  551. [_listPlayer playItemAtNumber:[NSNumber numberWithUnsignedInteger:nextIndex.unsignedIntegerValue]];
  552. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:self];
  553. return;
  554. }
  555. #endif
  556. if (mediaListCount > 1) {
  557. [_listPlayer next];
  558. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:self];
  559. } else {
  560. NSNumber *skipLength = [[NSUserDefaults standardUserDefaults] valueForKey:kVLCSettingPlaybackForwardSkipLength];
  561. [_mediaPlayer jumpForward:skipLength.intValue];
  562. }
  563. }
  564. - (void)previous
  565. {
  566. if (_mediaList.count > 1) {
  567. [_listPlayer previous];
  568. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:self];
  569. }
  570. else {
  571. NSNumber *skipLength = [[NSUserDefaults standardUserDefaults] valueForKey:kVLCSettingPlaybackBackwardSkipLength];
  572. [_mediaPlayer jumpBackward:skipLength.intValue];
  573. }
  574. }
  575. - (void)switchAspectRatio
  576. {
  577. if (_currentAspectRatio == VLCAspectRatioSixteenToTen) {
  578. _mediaPlayer.videoAspectRatio = NULL;
  579. _mediaPlayer.scaleFactor = 0;
  580. _currentAspectRatio = VLCAspectRatioDefault;
  581. } else {
  582. _currentAspectRatio++;
  583. if (_currentAspectRatio == VLCAspectRatioFillToScreen) {
  584. UIScreen *screen;
  585. if (![[UIDevice currentDevice] VLCHasExternalDisplay])
  586. screen = [UIScreen mainScreen];
  587. else
  588. screen = [UIScreen screens][1];
  589. float f_ar = screen.bounds.size.width / screen.bounds.size.height;
  590. if (f_ar == (float)(4.0/3.0) ||
  591. f_ar == (float)(1366./1024.)) {
  592. // all iPads
  593. _mediaPlayer.videoCropGeometry = "4:3";
  594. } else if (f_ar == (float)(2./3.) || f_ar == (float)(480./320.)) {
  595. // all other iPhones
  596. _mediaPlayer.videoCropGeometry = "16:10"; // libvlc doesn't support 2:3 crop
  597. } else if (f_ar == .5625) {
  598. // AirPlay
  599. _mediaPlayer.videoCropGeometry = "16:9";
  600. } else if (f_ar == (float)(640./1136.) ||
  601. f_ar == (float)(568./320.) ||
  602. f_ar == (float)(667./375.) ||
  603. f_ar == (float)(736./414.)) {
  604. // iPhone 5 and 6 and 6+
  605. _mediaPlayer.videoCropGeometry = "16:9";
  606. } else
  607. APLog(@"unknown screen format %f, can't crop", f_ar);
  608. } else {
  609. _mediaPlayer.videoAspectRatio = (char *)[[self stringForAspectRatio:_currentAspectRatio] UTF8String];
  610. _mediaPlayer.videoCropGeometry = NULL;
  611. }
  612. }
  613. if ([self.delegate respondsToSelector:@selector(showStatusMessage:forPlaybackController:)]) {
  614. [self.delegate showStatusMessage:[NSString stringWithFormat:NSLocalizedString(@"AR_CHANGED", nil), [self stringForAspectRatio:_currentAspectRatio]] forPlaybackController:self];
  615. }
  616. }
  617. - (NSString *)stringForAspectRatio:(VLCAspectRatio)ratio
  618. {
  619. switch (ratio) {
  620. case VLCAspectRatioFillToScreen:
  621. return NSLocalizedString(@"FILL_TO_SCREEN", nil);
  622. case VLCAspectRatioDefault:
  623. return NSLocalizedString(@"DEFAULT", nil);
  624. case VLCAspectRatioFourToThree:
  625. return @"4:3";
  626. case VLCAspectRatioSixteenToTen:
  627. return @"16:10";
  628. case VLCAspectRatioSixteenToNine:
  629. return @"16:9";
  630. default:
  631. NSAssert(NO, @"this shouldn't happen");
  632. }
  633. }
  634. - (void)setVideoTrackEnabled:(BOOL)enabled
  635. {
  636. if (!enabled)
  637. _mediaPlayer.currentVideoTrackIndex = -1;
  638. else if (_mediaPlayer.currentVideoTrackIndex == -1) {
  639. for (NSNumber *trackId in _mediaPlayer.videoTrackIndexes) {
  640. if ([trackId intValue] != -1) {
  641. _mediaPlayer.currentVideoTrackIndex = [trackId intValue];
  642. break;
  643. }
  644. }
  645. }
  646. }
  647. - (void)setVideoOutputView:(UIView *)videoOutputView
  648. {
  649. if (videoOutputView) {
  650. if ([_actualVideoOutputView superview] != nil)
  651. [_actualVideoOutputView removeFromSuperview];
  652. _actualVideoOutputView.frame = (CGRect){CGPointZero, videoOutputView.frame.size};
  653. [self setVideoTrackEnabled:true];
  654. [videoOutputView addSubview:_actualVideoOutputView];
  655. [_actualVideoOutputView layoutSubviews];
  656. [_actualVideoOutputView updateConstraints];
  657. [_actualVideoOutputView setNeedsLayout];
  658. } else
  659. [_actualVideoOutputView removeFromSuperview];
  660. _videoOutputViewWrapper = videoOutputView;
  661. }
  662. - (UIView *)videoOutputView
  663. {
  664. return _videoOutputViewWrapper;
  665. }
  666. #pragma mark - 360 Support
  667. #if !TARGET_OS_TV
  668. - (BOOL)updateViewpoint:(CGFloat)yaw pitch:(CGFloat)pitch roll:(CGFloat)roll fov:(CGFloat)fov absolute:(BOOL)absolute
  669. {
  670. return [_mediaPlayer updateViewpoint:yaw pitch:pitch roll:roll fov:fov absolute:absolute];
  671. }
  672. - (NSInteger)currentMediaProjection
  673. {
  674. VLCMedia *media = [_mediaPlayer media];
  675. NSInteger currentVideoTrackIndex = [_mediaPlayer currentVideoTrackIndex];
  676. if (media && currentVideoTrackIndex >= 0) {
  677. NSArray *tracksInfo = media.tracksInformation;
  678. for (NSDictionary *track in tracksInfo) {
  679. if ([track[VLCMediaTracksInformationType] isEqualToString:VLCMediaTracksInformationTypeVideo]) {
  680. return [track[VLCMediaTracksInformationVideoProjection] integerValue];
  681. }
  682. }
  683. }
  684. return -1;
  685. }
  686. #endif
  687. #pragma mark - equalizer
  688. - (void)setAmplification:(CGFloat)amplification forBand:(unsigned int)index
  689. {
  690. if (!_mediaPlayer.equalizerEnabled)
  691. [_mediaPlayer setEqualizerEnabled:YES];
  692. [_mediaPlayer setAmplification:amplification forBand:index];
  693. // For some reason we have to apply again preamp to apply change
  694. [_mediaPlayer setPreAmplification:[_mediaPlayer preAmplification]];
  695. }
  696. - (CGFloat)amplificationOfBand:(unsigned int)index
  697. {
  698. return [_mediaPlayer amplificationOfBand:index];
  699. }
  700. - (NSArray *)equalizerProfiles
  701. {
  702. return _mediaPlayer.equalizerProfiles;
  703. }
  704. - (void)resetEqualizerFromProfile:(unsigned int)profile
  705. {
  706. [[NSUserDefaults standardUserDefaults] setObject:@(profile) forKey:kVLCSettingEqualizerProfile];
  707. [_mediaPlayer resetEqualizerFromProfile:profile];
  708. }
  709. - (void)setPreAmplification:(CGFloat)preAmplification
  710. {
  711. if (!_mediaPlayer.equalizerEnabled)
  712. [_mediaPlayer setEqualizerEnabled:YES];
  713. [_mediaPlayer setPreAmplification:preAmplification];
  714. }
  715. - (CGFloat)preAmplification
  716. {
  717. return [_mediaPlayer preAmplification];
  718. }
  719. #pragma mark - AVSession delegate
  720. - (void)beginInterruption
  721. {
  722. if ([_mediaPlayer isPlaying]) {
  723. [_mediaPlayer pause];
  724. _shouldResumePlayingAfterInteruption = YES;
  725. }
  726. }
  727. - (void)endInterruption
  728. {
  729. if (_shouldResumePlayingAfterInteruption) {
  730. [_mediaPlayer play];
  731. _shouldResumePlayingAfterInteruption = NO;
  732. }
  733. }
  734. - (BOOL)areHeadphonesPlugged
  735. {
  736. NSArray *outputs = [[AVAudioSession sharedInstance] currentRoute].outputs;
  737. NSString *portName = [[outputs firstObject] portName];
  738. return [portName isEqualToString:@"Headphones"];
  739. }
  740. - (void)audioSessionRouteChange:(NSNotification *)notification
  741. {
  742. NSDictionary *userInfo = notification.userInfo;
  743. NSInteger routeChangeReason = [[userInfo valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];
  744. if (routeChangeReason == AVAudioSessionRouteChangeReasonRouteConfigurationChange)
  745. return;
  746. BOOL headphonesPlugged = [self areHeadphonesPlugged];
  747. if (_headphonesWasPlugged && !headphonesPlugged && [_mediaPlayer isPlaying]) {
  748. [_mediaPlayer pause];
  749. #if TARGET_OS_IOS
  750. [self _savePlaybackState];
  751. #endif
  752. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidPause object:self];
  753. }
  754. _headphonesWasPlugged = headphonesPlugged;
  755. }
  756. #pragma mark - Managing the media item
  757. #if TARGET_OS_IOS
  758. - (MLFile *)currentlyPlayingMediaFile {
  759. if (self.mediaList) {
  760. NSArray *results = [MLFile fileForURL:_mediaPlayer.media.url];
  761. return results.firstObject;
  762. }
  763. return nil;
  764. }
  765. #endif
  766. #pragma mark - metadata handling
  767. - (void)mediaDidFinishParsing:(VLCMedia *)aMedia
  768. {
  769. [self setNeedsMetadataUpdate];
  770. }
  771. - (void)mediaMetaDataDidChange:(VLCMedia*)aMedia
  772. {
  773. [self setNeedsMetadataUpdate];
  774. }
  775. - (void)setNeedsMetadataUpdate
  776. {
  777. if (_needsMetadataUpdate == NO) {
  778. _needsMetadataUpdate = YES;
  779. dispatch_async(dispatch_get_main_queue(), ^{
  780. [_metadata updateMetadataFromMediaPlayer:_mediaPlayer];
  781. _needsMetadataUpdate = NO;
  782. if ([self.delegate respondsToSelector:@selector(displayMetadataForPlaybackController:metadata:)])
  783. [self.delegate displayMetadataForPlaybackController:self metadata:_metadata];
  784. });
  785. }
  786. }
  787. #if TARGET_OS_IOS
  788. - (void)_recoverLastPlaybackStateOfItem:(MLFile *)item
  789. {
  790. if (item) {
  791. if (_mediaPlayer.numberOfAudioTracks > 2) {
  792. if (item.lastAudioTrack.intValue > 0)
  793. _mediaPlayer.currentAudioTrackIndex = item.lastAudioTrack.intValue;
  794. }
  795. if (_mediaPlayer.numberOfSubtitlesTracks > 2) {
  796. if (item.lastSubtitleTrack.intValue > 0)
  797. _mediaPlayer.currentVideoSubTitleIndex = item.lastSubtitleTrack.intValue;
  798. }
  799. CGFloat lastPosition = .0;
  800. NSInteger duration = 0;
  801. if (item.lastPosition)
  802. lastPosition = item.lastPosition.floatValue;
  803. duration = item.duration.intValue;
  804. if (lastPosition < .95 && _mediaPlayer.position < lastPosition && (duration * lastPosition - duration) < -50000) {
  805. NSInteger continuePlayback;
  806. if ([item isAlbumTrack] || [item isSupportedAudioFile])
  807. continuePlayback = [[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingContinueAudioPlayback] integerValue];
  808. else
  809. continuePlayback = [[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingContinuePlayback] integerValue];
  810. if (continuePlayback == 1) {
  811. _mediaPlayer.position = lastPosition;
  812. } else if (continuePlayback == 0) {
  813. VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"CONTINUE_PLAYBACK", nil)
  814. message:[NSString stringWithFormat:NSLocalizedString(@"CONTINUE_PLAYBACK_LONG", nil), item.title]
  815. delegate:self
  816. cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
  817. otherButtonTitles:NSLocalizedString(@"BUTTON_CONTINUE", nil), nil];
  818. alert.completion = ^(BOOL cancelled, NSInteger buttonIndex) {
  819. if (!cancelled) {
  820. _mediaPlayer.position = lastPosition;
  821. }
  822. };
  823. [alert show];
  824. }
  825. }
  826. }
  827. }
  828. #endif
  829. - (void)recoverDisplayedMetadata
  830. {
  831. if ([self.delegate respondsToSelector:@selector(displayMetadataForPlaybackController:metadata:)])
  832. [self.delegate displayMetadataForPlaybackController:self metadata:_metadata];
  833. }
  834. - (void)recoverPlaybackState
  835. {
  836. if ([self.delegate respondsToSelector:@selector(mediaPlayerStateChanged:isPlaying:currentMediaHasTrackToChooseFrom:currentMediaHasChapters:forPlaybackController:)])
  837. [self.delegate mediaPlayerStateChanged:_mediaPlayer.state
  838. isPlaying:self.isPlaying
  839. currentMediaHasTrackToChooseFrom:self.currentMediaHasTrackToChooseFrom
  840. currentMediaHasChapters:self.currentMediaHasChapters
  841. forPlaybackController:self];
  842. if ([self.delegate respondsToSelector:@selector(prepareForMediaPlayback:)])
  843. [self.delegate prepareForMediaPlayback:self];
  844. }
  845. - (void)scheduleSleepTimerWithInterval:(NSTimeInterval)timeInterval
  846. {
  847. if (_sleepTimer) {
  848. [_sleepTimer invalidate];
  849. _sleepTimer = nil;
  850. }
  851. _sleepTimer = [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(stopPlayback) userInfo:nil repeats:NO];
  852. }
  853. #pragma mark - background interaction
  854. - (void)applicationWillResignActive:(NSNotification *)aNotification
  855. {
  856. #if TARGET_OS_IOS
  857. [self _savePlaybackState];
  858. #endif
  859. if (![[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingContinueAudioInBackgroundKey] boolValue]) {
  860. if ([_mediaPlayer isPlaying]) {
  861. [_mediaPlayer pause];
  862. _shouldResumePlaying = YES;
  863. }
  864. }
  865. }
  866. - (void)applicationDidEnterBackground:(NSNotification *)notification
  867. {
  868. _preBackgroundWrapperView = _videoOutputViewWrapper;
  869. if (_mediaPlayer.audioTrackIndexes.count > 0)
  870. [self setVideoTrackEnabled:false];
  871. }
  872. - (void)applicationDidBecomeActive:(NSNotification *)notification
  873. {
  874. if (_preBackgroundWrapperView) {
  875. [self setVideoOutputView:_preBackgroundWrapperView];
  876. _preBackgroundWrapperView = nil;
  877. }
  878. [self setVideoTrackEnabled:true];
  879. if (_shouldResumePlaying) {
  880. _shouldResumePlaying = NO;
  881. [_listPlayer play];
  882. }
  883. }
  884. #pragma mark - remoteControlDelegate
  885. - (void)remoteControlServiceHitPause:(VLCRemoteControlService *)rcs
  886. {
  887. [_listPlayer pause];
  888. }
  889. - (void)remoteControlServiceHitPlay:(VLCRemoteControlService *)rcs
  890. {
  891. [_listPlayer play];
  892. }
  893. - (void)remoteControlServiceTogglePlayPause:(VLCRemoteControlService *)rcs
  894. {
  895. [self playPause];
  896. }
  897. - (void)remoteControlServiceHitStop:(VLCRemoteControlService *)rcs
  898. {
  899. //TODO handle stop playback entirely
  900. [_listPlayer stop];
  901. }
  902. - (BOOL)remoteControlServiceHitPlayNextIfPossible:(VLCRemoteControlService *)rcs
  903. {
  904. //TODO This doesn't handle shuffle or repeat yet
  905. return [_listPlayer next];
  906. }
  907. - (BOOL)remoteControlServiceHitPlayPreviousIfPossible:(VLCRemoteControlService *)rcs
  908. {
  909. //TODO This doesn't handle shuffle or repeat yet
  910. return [_listPlayer previous];
  911. }
  912. - (void)remoteControlService:(VLCRemoteControlService *)rcs jumpForwardInSeconds:(NSTimeInterval)seconds
  913. {
  914. [_mediaPlayer jumpForward:seconds];
  915. }
  916. - (void)remoteControlService:(VLCRemoteControlService *)rcs jumpBackwardInSeconds:(NSTimeInterval)seconds
  917. {
  918. [_mediaPlayer jumpBackward:seconds];
  919. }
  920. - (NSInteger)remoteControlServiceNumberOfMediaItemsinList:(VLCRemoteControlService *)rcs
  921. {
  922. return _mediaList.count;
  923. }
  924. - (void)remoteControlService:(VLCRemoteControlService *)rcs setPlaybackRate:(CGFloat)playbackRate
  925. {
  926. self.playbackRate = playbackRate;
  927. }
  928. #pragma mark - helpers
  929. - (NSDictionary *)mediaOptionsDictionary
  930. {
  931. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  932. return @{ kVLCSettingNetworkCaching : [defaults objectForKey:kVLCSettingNetworkCaching],
  933. kVLCSettingStretchAudio : [[defaults objectForKey:kVLCSettingStretchAudio] boolValue] ? kVLCSettingStretchAudioOnValue : kVLCSettingStretchAudioOffValue,
  934. kVLCSettingTextEncoding : [defaults objectForKey:kVLCSettingTextEncoding],
  935. kVLCSettingSkipLoopFilter : [defaults objectForKey:kVLCSettingSkipLoopFilter],
  936. kVLCSettingHardwareDecoding : [defaults objectForKey:kVLCSettingHardwareDecoding]};
  937. }
  938. @end