VLCPlaybackController.m 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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. VLCMediaPlayer *_mediaPlayer;
  47. BOOL _playerIsSetup;
  48. BOOL _shouldResumePlaying;
  49. BOOL _sessionWillRestart;
  50. BOOL _shouldResumePlayingAfterInteruption;
  51. NSString *_pathToExternalSubtitlesFile;
  52. int _itemInMediaListToBePlayedFirst;
  53. NSTimer *_sleepTimer;
  54. NSUInteger _currentAspectRatio;
  55. UIView *_videoOutputViewWrapper;
  56. UIView *_actualVideoOutputView;
  57. UIView *_preBackgroundWrapperView;
  58. BOOL _needsMetadataUpdate;
  59. BOOL _mediaWasJustStarted;
  60. BOOL _recheckForExistingThumbnail;
  61. BOOL _headphonesWasPlugged;
  62. NSLock *_playbackSessionManagementLock;
  63. VLCDialogProvider *_dialogProvider;
  64. NSMutableArray *_shuffleStack;
  65. }
  66. @end
  67. @implementation VLCPlaybackController
  68. #pragma mark instance management
  69. + (VLCPlaybackController *)sharedInstance
  70. {
  71. static VLCPlaybackController *sharedInstance = nil;
  72. static dispatch_once_t pred;
  73. dispatch_once(&pred, ^{
  74. sharedInstance = [VLCPlaybackController new];
  75. });
  76. return sharedInstance;
  77. }
  78. - (void)dealloc
  79. {
  80. _dialogProvider = nil;
  81. [[NSNotificationCenter defaultCenter] removeObserver:self];
  82. }
  83. - (instancetype)init
  84. {
  85. self = [super init];
  86. if (self) {
  87. // listen to audiosessions and appkit callback
  88. _headphonesWasPlugged = [self areHeadphonesPlugged];
  89. NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
  90. [defaultCenter addObserver:self selector:@selector(audioSessionRouteChange:)
  91. name:AVAudioSessionRouteChangeNotification object:nil];
  92. // appkit because we neeed to know when we go to background in order to stop the video, so that we don't crash
  93. [defaultCenter addObserver:self selector:@selector(applicationWillResignActive:)
  94. name:UIApplicationWillResignActiveNotification object:nil];
  95. [defaultCenter addObserver:self selector:@selector(applicationDidBecomeActive:)
  96. name:UIApplicationDidBecomeActiveNotification object:nil];
  97. [defaultCenter addObserver:self selector:@selector(applicationDidEnterBackground:)
  98. name:UIApplicationDidEnterBackgroundNotification object:nil];
  99. _metadata = [VLCMetaData new];
  100. _dialogProvider = [[VLCDialogProvider alloc] initWithLibrary:[VLCLibrary sharedLibrary] customUI:NO];
  101. _playbackSessionManagementLock = [[NSLock alloc] init];
  102. _shuffleMode = NO;
  103. _shuffleStack = [[NSMutableArray alloc] init];
  104. }
  105. return self;
  106. }
  107. - (VLCRemoteControlService *)remoteControlService
  108. {
  109. if (!_remoteControlService) {
  110. _remoteControlService = [[VLCRemoteControlService alloc] init];
  111. _remoteControlService.remoteControlServiceDelegate = self;
  112. }
  113. return _remoteControlService;
  114. }
  115. #pragma mark - playback management
  116. - (void)playMediaList:(VLCMediaList *)mediaList firstIndex:(NSInteger)index subtitlesFilePath:(NSString *)subsFilePath
  117. {
  118. self.mediaList = mediaList;
  119. _itemInMediaListToBePlayedFirst = (int)index;
  120. _pathToExternalSubtitlesFile = subsFilePath;
  121. _sessionWillRestart = self.isPlaying;
  122. self.isPlaying ? [self stopPlayback] : [self startPlayback];
  123. }
  124. - (void)startPlayback
  125. {
  126. if (_playerIsSetup) {
  127. APLog(@"%s: player is already setup, bailing out", __PRETTY_FUNCTION__);
  128. return;
  129. }
  130. BOOL ret = [_playbackSessionManagementLock tryLock];
  131. if (!ret) {
  132. APLog(@"%s: locking failed", __PRETTY_FUNCTION__);
  133. return;
  134. }
  135. #if TARGET_OS_IOS
  136. [[AVAudioSession sharedInstance] setDelegate:self];
  137. #endif
  138. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  139. if (!self.mediaList) {
  140. APLog(@"%s: no URL and no media list set, stopping playback", __PRETTY_FUNCTION__);
  141. [_playbackSessionManagementLock unlock];
  142. [self stopPlayback];
  143. return;
  144. }
  145. /* video decoding permanently fails if we don't provide a UIView to draw into on init
  146. * hence we provide one which is not attached to any view controller for off-screen drawing
  147. * and disable video decoding once playback started */
  148. _actualVideoOutputView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  149. _actualVideoOutputView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  150. _actualVideoOutputView.autoresizesSubviews = YES;
  151. if (_pathToExternalSubtitlesFile)
  152. _listPlayer = [[VLCMediaListPlayer alloc] initWithOptions:@[[NSString stringWithFormat:@"--%@=%@", kVLCSettingSubtitlesFilePath, _pathToExternalSubtitlesFile]] andDrawable:_actualVideoOutputView];
  153. else
  154. _listPlayer = [[VLCMediaListPlayer alloc] initWithDrawable:_actualVideoOutputView];
  155. /* to enable debug logging for the playback library instance, switch the boolean below
  156. * note that the library instance used for playback may not necessarily match the instance
  157. * used for media discovery or thumbnailing */
  158. _listPlayer.mediaPlayer.libraryInstance.debugLogging = NO;
  159. _mediaPlayer = _listPlayer.mediaPlayer;
  160. [_mediaPlayer setDelegate:self];
  161. if ([[defaults objectForKey:kVLCSettingPlaybackSpeedDefaultValue] floatValue] != 0)
  162. [_mediaPlayer setRate: [[defaults objectForKey:kVLCSettingPlaybackSpeedDefaultValue] floatValue]];
  163. if ([[defaults objectForKey:kVLCSettingDeinterlace] intValue] != 0)
  164. [_mediaPlayer setDeinterlaceFilter:@"blend"];
  165. else
  166. [_mediaPlayer setDeinterlaceFilter:nil];
  167. if (_pathToExternalSubtitlesFile)
  168. [_mediaPlayer addPlaybackSlave:[NSURL fileURLWithPath:_pathToExternalSubtitlesFile] type:VLCMediaPlaybackSlaveTypeSubtitle enforce:YES];
  169. VLCMedia *media = [_mediaList mediaAtIndex:_itemInMediaListToBePlayedFirst];
  170. [media parseWithOptions:VLCMediaParseLocal];
  171. media.delegate = self;
  172. [media addOptions:self.mediaOptionsDictionary];
  173. [_listPlayer setMediaList:self.mediaList];
  174. [_listPlayer setRepeatMode:VLCDoNotRepeat];
  175. [_playbackSessionManagementLock unlock];
  176. [self _playNewMedia];
  177. }
  178. - (void)_playNewMedia
  179. {
  180. BOOL ret = [_playbackSessionManagementLock tryLock];
  181. if (!ret) {
  182. APLog(@"%s: locking failed", __PRETTY_FUNCTION__);
  183. return;
  184. }
  185. // Set last selected equalizer profile
  186. unsigned int profile = (unsigned int)[[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingEqualizerProfile] integerValue];
  187. [_mediaPlayer resetEqualizerFromProfile:profile];
  188. [_mediaPlayer setPreAmplification:[_mediaPlayer preAmplification]];
  189. _mediaWasJustStarted = YES;
  190. [_mediaPlayer addObserver:self forKeyPath:@"time" options:0 context:nil];
  191. [_mediaPlayer addObserver:self forKeyPath:@"remainingTime" options:0 context:nil];
  192. [_listPlayer playItemAtNumber:@(_itemInMediaListToBePlayedFirst)];
  193. if ([self.delegate respondsToSelector:@selector(prepareForMediaPlayback:)])
  194. [self.delegate prepareForMediaPlayback:self];
  195. _currentAspectRatio = VLCAspectRatioDefault;
  196. _mediaPlayer.videoAspectRatio = NULL;
  197. _mediaPlayer.scaleFactor = 0;
  198. [[self remoteControlService] subscribeToRemoteCommands];
  199. _playerIsSetup = YES;
  200. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidStart object:self];
  201. [_playbackSessionManagementLock unlock];
  202. }
  203. - (void)stopPlayback
  204. {
  205. BOOL ret = [_playbackSessionManagementLock tryLock];
  206. if (!ret) {
  207. APLog(@"%s: locking failed", __PRETTY_FUNCTION__);
  208. return;
  209. }
  210. if (_mediaPlayer) {
  211. @try {
  212. [_mediaPlayer removeObserver:self forKeyPath:@"time"];
  213. [_mediaPlayer removeObserver:self forKeyPath:@"remainingTime"];
  214. }
  215. @catch (NSException *exception) {
  216. APLog(@"we weren't an observer yet");
  217. }
  218. if (_mediaPlayer.media) {
  219. [_mediaPlayer pause];
  220. #if TARGET_OS_IOS
  221. [self _savePlaybackState];
  222. #endif
  223. [_mediaPlayer stop];
  224. }
  225. _mediaPlayer = nil;
  226. _listPlayer = nil;
  227. }
  228. if (!_sessionWillRestart) {
  229. _mediaList = nil;
  230. if (_pathToExternalSubtitlesFile) {
  231. NSFileManager *fileManager = [NSFileManager defaultManager];
  232. if ([fileManager fileExistsAtPath:_pathToExternalSubtitlesFile])
  233. [fileManager removeItemAtPath:_pathToExternalSubtitlesFile error:nil];
  234. _pathToExternalSubtitlesFile = nil;
  235. }
  236. }
  237. _playerIsSetup = NO;
  238. [_shuffleStack removeAllObjects];
  239. if (_errorCallback && _mediaPlayer.state == VLCMediaPlayerStateError && !_sessionWillRestart)
  240. [[UIApplication sharedApplication] openURL:_errorCallback];
  241. else if (_successCallback && !_sessionWillRestart)
  242. [[UIApplication sharedApplication] openURL:_successCallback];
  243. [[self remoteControlService] unsubscribeFromRemoteCommands];
  244. [_playbackSessionManagementLock unlock];
  245. if (!_sessionWillRestart) {
  246. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidStop object:self];
  247. } else {
  248. _sessionWillRestart = NO;
  249. [self startPlayback];
  250. }
  251. }
  252. #if TARGET_OS_IOS
  253. - (void)_savePlaybackState
  254. {
  255. @try {
  256. [[MLMediaLibrary sharedMediaLibrary] save];
  257. }
  258. @catch (NSException *exception) {
  259. APLog(@"saving playback state failed");
  260. }
  261. NSArray *files = [MLFile fileForURL:_mediaPlayer.media.url];
  262. MLFile *fileItem = files.firstObject;
  263. if (!fileItem) {
  264. APLog(@"couldn't find file, not saving playback progress");
  265. return;
  266. }
  267. @try {
  268. float position = _mediaPlayer.position;
  269. fileItem.lastPosition = @(position);
  270. fileItem.lastAudioTrack = @(_mediaPlayer.currentAudioTrackIndex);
  271. fileItem.lastSubtitleTrack = @(_mediaPlayer.currentVideoSubTitleIndex);
  272. if (position > .95)
  273. return;
  274. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  275. NSString* newThumbnailPath = [searchPaths[0] stringByAppendingPathComponent:@"VideoSnapshots"];
  276. NSFileManager *fileManager = [NSFileManager defaultManager];
  277. if (![fileManager fileExistsAtPath:newThumbnailPath])
  278. [fileManager createDirectoryAtPath:newThumbnailPath withIntermediateDirectories:YES attributes:nil error:nil];
  279. newThumbnailPath = [newThumbnailPath stringByAppendingPathComponent:fileItem.objectID.URIRepresentation.lastPathComponent];
  280. [_mediaPlayer saveVideoSnapshotAt:newThumbnailPath withWidth:0 andHeight:0];
  281. _recheckForExistingThumbnail = YES;
  282. [self performSelector:@selector(_updateStoredThumbnailForFile:) withObject:fileItem afterDelay:.25];
  283. }
  284. @catch (NSException *exception) {
  285. APLog(@"failed to save current media state - file removed?");
  286. }
  287. }
  288. #endif
  289. #if TARGET_OS_IOS
  290. - (void)_updateStoredThumbnailForFile:(MLFile *)fileItem
  291. {
  292. NSFileManager *fileManager = [NSFileManager defaultManager];
  293. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  294. NSString* newThumbnailPath = [searchPaths[0] stringByAppendingPathComponent:@"VideoSnapshots"];
  295. newThumbnailPath = [newThumbnailPath stringByAppendingPathComponent:fileItem.objectID.URIRepresentation.lastPathComponent];
  296. if (![fileManager fileExistsAtPath:newThumbnailPath]) {
  297. if (_recheckForExistingThumbnail) {
  298. [self performSelector:@selector(_updateStoredThumbnailForFile:) withObject:fileItem afterDelay:1.];
  299. _recheckForExistingThumbnail = NO;
  300. } else
  301. return;
  302. }
  303. UIImage *newThumbnail = [UIImage imageWithContentsOfFile:newThumbnailPath];
  304. if (!newThumbnail) {
  305. if (_recheckForExistingThumbnail) {
  306. [self performSelector:@selector(_updateStoredThumbnailForFile:) withObject:fileItem afterDelay:1.];
  307. _recheckForExistingThumbnail = NO;
  308. } else
  309. return;
  310. }
  311. @try {
  312. [fileItem setComputedThumbnailScaledForDevice:newThumbnail];
  313. }
  314. @catch (NSException *exception) {
  315. APLog(@"updating thumbnail failed");
  316. }
  317. [fileManager removeItemAtPath:newThumbnailPath error:nil];
  318. }
  319. #endif
  320. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  321. {
  322. if (_mediaWasJustStarted) {
  323. _mediaWasJustStarted = NO;
  324. #if TARGET_OS_IOS
  325. if (self.mediaList) {
  326. NSArray *matches = [MLFile fileForURL:_mediaPlayer.media.url];
  327. MLFile *item = matches.firstObject;
  328. [self _recoverLastPlaybackStateOfItem:item];
  329. }
  330. #else
  331. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  332. BOOL bValue = [defaults boolForKey:kVLCSettingUseSPDIF];
  333. if (bValue) {
  334. _mediaPlayer.audio.passthrough = bValue;
  335. }
  336. #endif
  337. }
  338. if ([self.delegate respondsToSelector:@selector(playbackPositionUpdated:)])
  339. [self.delegate playbackPositionUpdated:self];
  340. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackPositionUpdated
  341. object:self];
  342. }
  343. - (NSInteger)mediaDuration
  344. {
  345. return _mediaPlayer.media.length.intValue;;
  346. }
  347. - (BOOL)isPlaying
  348. {
  349. return _mediaPlayer.isPlaying;
  350. }
  351. - (VLCRepeatMode)repeatMode
  352. {
  353. return _listPlayer.repeatMode;
  354. }
  355. - (void)setRepeatMode:(VLCRepeatMode)repeatMode
  356. {
  357. _listPlayer.repeatMode = repeatMode;
  358. }
  359. - (BOOL)currentMediaHasChapters
  360. {
  361. return [_mediaPlayer numberOfTitles] > 1 || [_mediaPlayer numberOfChaptersForTitle:_mediaPlayer.currentTitleIndex] > 1;
  362. }
  363. - (BOOL)currentMediaHasTrackToChooseFrom
  364. {
  365. return [[_mediaPlayer audioTrackIndexes] count] > 2 || [[_mediaPlayer videoSubTitlesIndexes] count] > 1;
  366. }
  367. - (NSNumber *)playbackTime
  368. {
  369. return _mediaPlayer.time.value;
  370. }
  371. - (float)playbackRate
  372. {
  373. return _mediaPlayer.rate;
  374. }
  375. - (void)setPlaybackRate:(float)playbackRate
  376. {
  377. [_mediaPlayer setRate:playbackRate];
  378. _metadata.playbackRate = @(_mediaPlayer.rate);
  379. }
  380. - (void)setAudioDelay:(float)audioDelay
  381. {
  382. _mediaPlayer.currentAudioPlaybackDelay = 1000000.*audioDelay;
  383. }
  384. - (float)audioDelay
  385. {
  386. return _mediaPlayer.currentAudioPlaybackDelay/1000000.;
  387. }
  388. -(void)setSubtitleDelay:(float)subtitleDeleay
  389. {
  390. _mediaPlayer.currentVideoSubTitleDelay = 1000000.*subtitleDeleay;
  391. }
  392. - (float)subtitleDelay
  393. {
  394. return _mediaPlayer.currentVideoSubTitleDelay/1000000.;
  395. }
  396. - (NSInteger)indexOfCurrentAudioTrack
  397. {
  398. return [_mediaPlayer.audioTrackIndexes indexOfObject:@(_mediaPlayer.currentAudioTrackIndex)];
  399. }
  400. - (NSInteger)indexOfCurrentSubtitleTrack
  401. {
  402. return [_mediaPlayer.videoSubTitlesIndexes indexOfObject:@(_mediaPlayer.currentVideoSubTitleIndex)];
  403. }
  404. - (NSInteger)indexOfCurrentChapter
  405. {
  406. return _mediaPlayer.currentChapterIndex;
  407. }
  408. - (NSInteger)indexOfCurrentTitle
  409. {
  410. return _mediaPlayer.currentTitleIndex;
  411. }
  412. - (NSInteger)numberOfAudioTracks
  413. {
  414. return _mediaPlayer.audioTrackIndexes.count;
  415. }
  416. - (NSInteger)numberOfVideoSubtitlesIndexes
  417. {
  418. return _mediaPlayer.videoSubTitlesIndexes.count;
  419. }
  420. - (NSInteger)numberOfTitles
  421. {
  422. return [_mediaPlayer numberOfTitles];
  423. }
  424. - (NSInteger)numberOfChaptersForCurrentTitle
  425. {
  426. return [_mediaPlayer numberOfChaptersForTitle:_mediaPlayer.currentTitleIndex];
  427. }
  428. - (NSString *)videoSubtitleNameAtIndex:(NSInteger)index
  429. {
  430. if (index >= 0 && index < _mediaPlayer.videoSubTitlesNames.count)
  431. return _mediaPlayer.videoSubTitlesNames[index];
  432. return nil;
  433. }
  434. - (NSString *)audioTrackNameAtIndex:(NSInteger)index
  435. {
  436. if (index >= 0 && index < _mediaPlayer.audioTrackNames.count)
  437. return _mediaPlayer.audioTrackNames[index];
  438. return nil;
  439. }
  440. - (NSDictionary *)titleDescriptionsDictAtIndex:(NSInteger)index
  441. {
  442. if (index >= 0 && index < _mediaPlayer.titleDescriptions.count)
  443. return _mediaPlayer.titleDescriptions[index];
  444. return nil;
  445. }
  446. - (NSDictionary *)chapterDescriptionsDictAtIndex:(NSInteger)index
  447. {
  448. NSArray *chapterDescriptions = [_mediaPlayer chapterDescriptionsOfTitle:_mediaPlayer.currentTitleIndex];
  449. if (index >= 0 && index < chapterDescriptions.count)
  450. return chapterDescriptions[index];
  451. return nil;
  452. }
  453. - (void)selectAudioTrackAtIndex:(NSInteger)index
  454. {
  455. if (index >= 0 && index < _mediaPlayer.audioTrackIndexes.count) {
  456. //we can cast this cause we won't have more than 2 million audiotracks
  457. _mediaPlayer.currentAudioTrackIndex = [_mediaPlayer.audioTrackIndexes[index] intValue];
  458. }
  459. }
  460. - (void)selectVideoSubtitleAtIndex:(NSInteger)index
  461. {
  462. if (index >= 0 && index < _mediaPlayer.videoSubTitlesIndexes.count) {
  463. _mediaPlayer.currentVideoSubTitleIndex = [_mediaPlayer.videoSubTitlesIndexes[index] intValue];
  464. }
  465. }
  466. - (void)selectTitleAtIndex:(NSInteger)index
  467. {
  468. if (index >= 0 && index < [_mediaPlayer numberOfTitles]) {
  469. //we can cast this cause we won't have more than 2 million titles
  470. _mediaPlayer.currentTitleIndex = (int)index;
  471. }
  472. }
  473. - (void)selectChapterAtIndex:(NSInteger)index
  474. {
  475. if (index >= 0 && index < [self numberOfChaptersForCurrentTitle]) {
  476. //we can cast this cause we won't have more than 2 million chapters
  477. _mediaPlayer.currentChapterIndex = (int)index;
  478. }
  479. }
  480. - (void)mediaPlayerStateChanged:(NSNotification *)aNotification
  481. {
  482. VLCMediaPlayerState currentState = _mediaPlayer.state;
  483. if (currentState == VLCMediaPlayerStateBuffering) {
  484. /* attach delegate */
  485. _mediaPlayer.media.delegate = self;
  486. /* on-the-fly values through hidden API */
  487. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  488. [_mediaPlayer performSelector:@selector(setTextRendererFont:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFont]];
  489. [_mediaPlayer performSelector:@selector(setTextRendererFontSize:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFontSize]];
  490. [_mediaPlayer performSelector:@selector(setTextRendererFontColor:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFontColor]];
  491. [_mediaPlayer performSelector:@selector(setTextRendererFontForceBold:) withObject:[defaults objectForKey:kVLCSettingSubtitlesBoldFont]];
  492. } else if (currentState == VLCMediaPlayerStateError) {
  493. APLog(@"Playback failed");
  494. dispatch_async(dispatch_get_main_queue(),^{
  495. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidFail object:self];
  496. });
  497. _sessionWillRestart = NO;
  498. [self stopPlayback];
  499. } else if (currentState == VLCMediaPlayerStateEnded || currentState == VLCMediaPlayerStateStopped) {
  500. [_listPlayer.mediaList lock];
  501. NSUInteger listCount = _listPlayer.mediaList.count;
  502. if ([_listPlayer.mediaList indexOfMedia:_mediaPlayer.media] == listCount - 1 && self.repeatMode == VLCDoNotRepeat) {
  503. [_listPlayer.mediaList unlock];
  504. _sessionWillRestart = NO;
  505. [self stopPlayback];
  506. return;
  507. } else if (listCount > 1) {
  508. [_listPlayer.mediaList unlock];
  509. [_listPlayer next];
  510. } else
  511. [_listPlayer.mediaList unlock];
  512. }
  513. if ([self.delegate respondsToSelector:@selector(mediaPlayerStateChanged:isPlaying:currentMediaHasTrackToChooseFrom:currentMediaHasChapters:forPlaybackController:)])
  514. [self.delegate mediaPlayerStateChanged:currentState
  515. isPlaying:_mediaPlayer.isPlaying
  516. currentMediaHasTrackToChooseFrom:self.currentMediaHasTrackToChooseFrom
  517. currentMediaHasChapters:self.currentMediaHasChapters
  518. forPlaybackController:self];
  519. [self setNeedsMetadataUpdate];
  520. }
  521. #pragma mark - playback controls
  522. - (void)playPause
  523. {
  524. if ([_mediaPlayer isPlaying]) {
  525. [_listPlayer pause];
  526. #if TARGET_OS_IOS
  527. [self _savePlaybackState];
  528. #endif
  529. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidPause object:self];
  530. } else {
  531. [_listPlayer play];
  532. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidResume object:self];
  533. }
  534. }
  535. - (void)next
  536. {
  537. NSInteger mediaListCount = _mediaList.count;
  538. #if TARGET_OS_IOS
  539. if (mediaListCount > 2 && _shuffleMode) {
  540. NSNumber *nextIndex;
  541. NSUInteger currentIndex = [_mediaList indexOfMedia:_listPlayer.mediaPlayer.media];
  542. //Reached end of playlist
  543. if (_shuffleStack.count + 1 == mediaListCount) {
  544. if ([self repeatMode] == VLCDoNotRepeat)
  545. return;
  546. [_shuffleStack removeAllObjects];
  547. }
  548. [_shuffleStack addObject:[NSNumber numberWithUnsignedInteger:currentIndex]];
  549. do {
  550. nextIndex = [NSNumber numberWithUnsignedInt:arc4random_uniform((uint32_t)mediaListCount)];
  551. } while (currentIndex == nextIndex.unsignedIntegerValue || [_shuffleStack containsObject:nextIndex]);
  552. [_listPlayer playItemAtNumber:[NSNumber numberWithUnsignedInteger:nextIndex.unsignedIntegerValue]];
  553. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:self];
  554. return;
  555. }
  556. #endif
  557. if (mediaListCount > 1) {
  558. [_listPlayer next];
  559. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:self];
  560. } else {
  561. NSNumber *skipLength = [[NSUserDefaults standardUserDefaults] valueForKey:kVLCSettingPlaybackForwardSkipLength];
  562. [_mediaPlayer jumpForward:skipLength.intValue];
  563. }
  564. }
  565. - (void)previous
  566. {
  567. if (_mediaList.count > 1) {
  568. [_listPlayer previous];
  569. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:self];
  570. }
  571. else {
  572. NSNumber *skipLength = [[NSUserDefaults standardUserDefaults] valueForKey:kVLCSettingPlaybackBackwardSkipLength];
  573. [_mediaPlayer jumpBackward:skipLength.intValue];
  574. }
  575. }
  576. - (void)switchAspectRatio
  577. {
  578. if (_currentAspectRatio == VLCAspectRatioSixteenToTen) {
  579. _mediaPlayer.videoAspectRatio = NULL;
  580. _mediaPlayer.scaleFactor = 0;
  581. _currentAspectRatio = VLCAspectRatioDefault;
  582. } else {
  583. _currentAspectRatio++;
  584. if (_currentAspectRatio == VLCAspectRatioFillToScreen) {
  585. UIScreen *screen;
  586. if (![[UIDevice currentDevice] VLCHasExternalDisplay])
  587. screen = [UIScreen mainScreen];
  588. else
  589. screen = [UIScreen screens][1];
  590. float f_ar = screen.bounds.size.width / screen.bounds.size.height;
  591. if (f_ar == (float)(4.0/3.0) ||
  592. f_ar == (float)(1366./1024.)) {
  593. // all iPads
  594. _mediaPlayer.videoCropGeometry = "4:3";
  595. } else if (f_ar == (float)(2./3.) || f_ar == (float)(480./320.)) {
  596. // all other iPhones
  597. _mediaPlayer.videoCropGeometry = "16:10"; // libvlc doesn't support 2:3 crop
  598. } else if (f_ar == .5625) {
  599. // AirPlay
  600. _mediaPlayer.videoCropGeometry = "16:9";
  601. } else if (f_ar == (float)(640./1136.) ||
  602. f_ar == (float)(568./320.) ||
  603. f_ar == (float)(667./375.) ||
  604. f_ar == (float)(736./414.)) {
  605. // iPhone 5 and 6 and 6+
  606. _mediaPlayer.videoCropGeometry = "16:9";
  607. } else
  608. APLog(@"unknown screen format %f, can't crop", f_ar);
  609. } else {
  610. _mediaPlayer.videoAspectRatio = (char *)[[self stringForAspectRatio:_currentAspectRatio] UTF8String];
  611. _mediaPlayer.videoCropGeometry = NULL;
  612. }
  613. }
  614. if ([self.delegate respondsToSelector:@selector(showStatusMessage:forPlaybackController:)]) {
  615. [self.delegate showStatusMessage:[NSString stringWithFormat:NSLocalizedString(@"AR_CHANGED", nil), [self stringForAspectRatio:_currentAspectRatio]] forPlaybackController:self];
  616. }
  617. }
  618. - (NSString *)stringForAspectRatio:(VLCAspectRatio)ratio
  619. {
  620. switch (ratio) {
  621. case VLCAspectRatioFillToScreen:
  622. return NSLocalizedString(@"FILL_TO_SCREEN", nil);
  623. case VLCAspectRatioDefault:
  624. return NSLocalizedString(@"DEFAULT", nil);
  625. case VLCAspectRatioFourToThree:
  626. return @"4:3";
  627. case VLCAspectRatioSixteenToTen:
  628. return @"16:10";
  629. case VLCAspectRatioSixteenToNine:
  630. return @"16:9";
  631. default:
  632. NSAssert(NO, @"this shouldn't happen");
  633. }
  634. }
  635. - (void)setVideoTrackEnabled:(BOOL)enabled
  636. {
  637. if (!enabled)
  638. _mediaPlayer.currentVideoTrackIndex = -1;
  639. else if (_mediaPlayer.currentVideoTrackIndex == -1) {
  640. for (NSNumber *trackId in _mediaPlayer.videoTrackIndexes) {
  641. if ([trackId intValue] != -1) {
  642. _mediaPlayer.currentVideoTrackIndex = [trackId intValue];
  643. break;
  644. }
  645. }
  646. }
  647. }
  648. - (void)setVideoOutputView:(UIView *)videoOutputView
  649. {
  650. if (videoOutputView) {
  651. if ([_actualVideoOutputView superview] != nil)
  652. [_actualVideoOutputView removeFromSuperview];
  653. _actualVideoOutputView.frame = (CGRect){CGPointZero, videoOutputView.frame.size};
  654. [self setVideoTrackEnabled:true];
  655. [videoOutputView addSubview:_actualVideoOutputView];
  656. [_actualVideoOutputView layoutSubviews];
  657. [_actualVideoOutputView updateConstraints];
  658. [_actualVideoOutputView setNeedsLayout];
  659. } else
  660. [_actualVideoOutputView removeFromSuperview];
  661. _videoOutputViewWrapper = videoOutputView;
  662. }
  663. - (UIView *)videoOutputView
  664. {
  665. return _videoOutputViewWrapper;
  666. }
  667. #pragma mark - 360 Support
  668. #if !TARGET_OS_TV
  669. - (BOOL)updateViewpoint:(CGFloat)yaw pitch:(CGFloat)pitch roll:(CGFloat)roll fov:(CGFloat)fov absolute:(BOOL)absolute
  670. {
  671. return [_mediaPlayer updateViewpoint:yaw pitch:pitch roll:roll fov:fov absolute:absolute];
  672. }
  673. - (NSInteger)currentMediaProjection
  674. {
  675. VLCMedia *media = [_mediaPlayer media];
  676. NSInteger currentVideoTrackIndex = [_mediaPlayer currentVideoTrackIndex];
  677. if (media && currentVideoTrackIndex >= 0) {
  678. NSArray *tracksInfo = media.tracksInformation;
  679. for (NSDictionary *track in tracksInfo) {
  680. if ([track[VLCMediaTracksInformationType] isEqualToString:VLCMediaTracksInformationTypeVideo]) {
  681. return [track[VLCMediaTracksInformationVideoProjection] integerValue];
  682. }
  683. }
  684. }
  685. return -1;
  686. }
  687. #endif
  688. #pragma mark - equalizer
  689. - (void)setAmplification:(CGFloat)amplification forBand:(unsigned int)index
  690. {
  691. if (!_mediaPlayer.equalizerEnabled)
  692. [_mediaPlayer setEqualizerEnabled:YES];
  693. [_mediaPlayer setAmplification:amplification forBand:index];
  694. // For some reason we have to apply again preamp to apply change
  695. [_mediaPlayer setPreAmplification:[_mediaPlayer preAmplification]];
  696. }
  697. - (CGFloat)amplificationOfBand:(unsigned int)index
  698. {
  699. return [_mediaPlayer amplificationOfBand:index];
  700. }
  701. - (NSArray *)equalizerProfiles
  702. {
  703. return _mediaPlayer.equalizerProfiles;
  704. }
  705. - (void)resetEqualizerFromProfile:(unsigned int)profile
  706. {
  707. [[NSUserDefaults standardUserDefaults] setObject:@(profile) forKey:kVLCSettingEqualizerProfile];
  708. [_mediaPlayer resetEqualizerFromProfile:profile];
  709. }
  710. - (void)setPreAmplification:(CGFloat)preAmplification
  711. {
  712. if (!_mediaPlayer.equalizerEnabled)
  713. [_mediaPlayer setEqualizerEnabled:YES];
  714. [_mediaPlayer setPreAmplification:preAmplification];
  715. }
  716. - (CGFloat)preAmplification
  717. {
  718. return [_mediaPlayer preAmplification];
  719. }
  720. #pragma mark - AVSession delegate
  721. - (void)beginInterruption
  722. {
  723. if ([_mediaPlayer isPlaying]) {
  724. [_mediaPlayer pause];
  725. _shouldResumePlayingAfterInteruption = YES;
  726. }
  727. }
  728. - (void)endInterruption
  729. {
  730. if (_shouldResumePlayingAfterInteruption) {
  731. [_mediaPlayer play];
  732. _shouldResumePlayingAfterInteruption = NO;
  733. }
  734. }
  735. - (BOOL)areHeadphonesPlugged
  736. {
  737. NSArray *outputs = [[AVAudioSession sharedInstance] currentRoute].outputs;
  738. NSString *portName = [[outputs firstObject] portName];
  739. return [portName isEqualToString:@"Headphones"];
  740. }
  741. - (void)audioSessionRouteChange:(NSNotification *)notification
  742. {
  743. NSDictionary *userInfo = notification.userInfo;
  744. NSInteger routeChangeReason = [[userInfo valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];
  745. if (routeChangeReason == AVAudioSessionRouteChangeReasonRouteConfigurationChange)
  746. return;
  747. BOOL headphonesPlugged = [self areHeadphonesPlugged];
  748. if (_headphonesWasPlugged && !headphonesPlugged && [_mediaPlayer isPlaying]) {
  749. [_mediaPlayer pause];
  750. #if TARGET_OS_IOS
  751. [self _savePlaybackState];
  752. #endif
  753. [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidPause object:self];
  754. }
  755. _headphonesWasPlugged = headphonesPlugged;
  756. }
  757. #pragma mark - Managing the media item
  758. - (VLCMedia *)currentlyPlayingMedia
  759. {
  760. return _mediaPlayer.media;
  761. }
  762. #pragma mark - metadata handling
  763. - (void)performNavigationAction:(VLCMediaPlaybackNavigationAction)action
  764. {
  765. [_mediaPlayer performNavigationAction:action];
  766. }
  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