VLCPlaybackController.m 38 KB

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