VLCPlaybackController.m 38 KB

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