VLCMediaPlayer.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*****************************************************************************
  2. * VLCMediaPlayer.m: VLCKit.framework VLCMediaPlayer implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2007 the VideoLAN team
  6. * $Id$
  7. *
  8. * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  9. * Faustion Osuna <enrique.osuna # gmail.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  24. *****************************************************************************/
  25. #import "VLCLibrary.h"
  26. #import "VLCMediaPlayer.h"
  27. #import "VLCEventManager.h"
  28. #import "VLCLibVLCBridging.h"
  29. #import "VLCVideoView.h"
  30. #ifdef HAVE_CONFIG_H
  31. # include "config.h"
  32. #endif
  33. /* prevent system sleep */
  34. #import <CoreServices/CoreServices.h>
  35. #include <vlc/vlc.h>
  36. /* Notification Messages */
  37. NSString * VLCMediaPlayerTimeChanged = @"VLCMediaPlayerTimeChanged";
  38. NSString * VLCMediaPlayerStateChanged = @"VLCMediaPlayerStateChanged";
  39. NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state)
  40. {
  41. static NSString * stateToStrings[] = {
  42. [VLCMediaPlayerStateStopped] = @"VLCMediaPlayerStateStopped",
  43. [VLCMediaPlayerStateOpening] = @"VLCMediaPlayerStateOpening",
  44. [VLCMediaPlayerStateBuffering] = @"VLCMediaPlayerStateBuffering",
  45. [VLCMediaPlayerStateEnded] = @"VLCMediaPlayerStateEnded",
  46. [VLCMediaPlayerStateError] = @"VLCMediaPlayerStateError",
  47. [VLCMediaPlayerStatePlaying] = @"VLCMediaPlayerStatePlaying",
  48. [VLCMediaPlayerStatePaused] = @"VLCMediaPlayerStatePaused"
  49. };
  50. return stateToStrings[state];
  51. }
  52. /* libvlc event callback */
  53. static void HandleMediaInstanceVolumeChanged(const libvlc_event_t * event, void * self)
  54. {
  55. [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self
  56. withDelegateMethod:@selector(mediaPlayerVolumeChanged:)
  57. withNotificationName:VLCMediaPlayerVolumeChanged];
  58. }
  59. static void HandleMediaTimeChanged(const libvlc_event_t * event, void * self)
  60. {
  61. NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  62. [[VLCEventManager sharedManager] callOnMainThreadObject:self
  63. withMethod:@selector(mediaPlayerTimeChanged:)
  64. withArgumentAsObject:[NSNumber numberWithLongLong:event->u.media_player_time_changed.new_time]];
  65. [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self
  66. withDelegateMethod:@selector(mediaPlayerTimeChanged:)
  67. withNotificationName:VLCMediaPlayerTimeChanged];
  68. [pool release];
  69. }
  70. static void HandleMediaPositionChanged(const libvlc_event_t * event, void * self)
  71. {
  72. NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  73. [[VLCEventManager sharedManager] callOnMainThreadObject:self
  74. withMethod:@selector(mediaPlayerPositionChanged:)
  75. withArgumentAsObject:[NSNumber numberWithFloat:event->u.media_player_position_changed.new_position]];
  76. [pool release];
  77. }
  78. static void HandleMediaInstanceStateChanged(const libvlc_event_t * event, void * self)
  79. {
  80. VLCMediaPlayerState newState;
  81. if( event->type == libvlc_MediaPlayerPlaying )
  82. newState = VLCMediaPlayerStatePlaying;
  83. else if( event->type == libvlc_MediaPlayerPaused )
  84. newState = VLCMediaPlayerStatePaused;
  85. else if( event->type == libvlc_MediaPlayerEndReached )
  86. newState = VLCMediaPlayerStateStopped;
  87. else if( event->type == libvlc_MediaPlayerEncounteredError )
  88. newState = VLCMediaPlayerStateError;
  89. else
  90. {
  91. NSLog(@"%s: Unknown event", __FUNCTION__);
  92. return;
  93. }
  94. NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  95. [[VLCEventManager sharedManager] callOnMainThreadObject:self
  96. withMethod:@selector(mediaPlayerStateChanged:)
  97. withArgumentAsObject:[NSNumber numberWithInt:newState]];
  98. [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self
  99. withDelegateMethod:@selector(mediaPlayerStateChanged:)
  100. withNotificationName:VLCMediaPlayerStateChanged];
  101. [pool release];
  102. }
  103. // TODO: Documentation
  104. @interface VLCMediaPlayer (Private)
  105. - (id)initWithDrawable:(id)aDrawable;
  106. - (void)registerObservers;
  107. - (void)unregisterObservers;
  108. - (void)mediaPlayerTimeChanged:(NSNumber *)newTime;
  109. - (void)mediaPlayerPositionChanged:(NSNumber *)newTime;
  110. - (void)mediaPlayerStateChanged:(NSNumber *)newState;
  111. @end
  112. @implementation VLCMediaPlayer
  113. /* Bindings */
  114. + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key
  115. {
  116. static NSDictionary * dict = nil;
  117. NSSet * superKeyPaths;
  118. if( !dict )
  119. {
  120. dict = [[NSDictionary dictionaryWithObjectsAndKeys:
  121. [NSSet setWithObject:@"state"], @"playing",
  122. [NSSet setWithObjects:@"state", @"media", nil], @"seekable",
  123. [NSSet setWithObjects:@"state", @"media", nil], @"canPause",
  124. [NSSet setWithObjects:@"state", @"media", nil], @"description",
  125. nil] retain];
  126. }
  127. if( (superKeyPaths = [super keyPathsForValuesAffectingValueForKey: key]) )
  128. {
  129. NSMutableSet * ret = [NSMutableSet setWithSet:[dict objectForKey: key]];
  130. [ret unionSet:superKeyPaths];
  131. return ret;
  132. }
  133. return [dict objectForKey: key];
  134. }
  135. /* Contructor */
  136. - (id)init
  137. {
  138. return [self initWithDrawable:nil];
  139. }
  140. - (id)initWithVideoView:(VLCVideoView *)aVideoView
  141. {
  142. return [self initWithDrawable: aVideoView];
  143. }
  144. - (id)initWithVideoLayer:(VLCVideoLayer *)aVideoLayer
  145. {
  146. return [self initWithDrawable: aVideoLayer];
  147. }
  148. - (void)release
  149. {
  150. @synchronized(self)
  151. {
  152. if([self retainCount] <= 1)
  153. {
  154. /* We must make sure we won't receive new event after an upcoming dealloc
  155. * We also may receive a -retain in some event callback that may occcur
  156. * Before libvlc_event_detach. So this can't happen in dealloc */
  157. [self unregisterObservers];
  158. }
  159. [super release];
  160. }
  161. }
  162. - (void)dealloc
  163. {
  164. // Always get rid of the delegate first so we can stop sending messages to it
  165. // TODO: Should we tell the delegate that we're shutting down?
  166. delegate = nil;
  167. libvlc_media_player_release((libvlc_media_player_t *)instance);
  168. // Get rid of everything else
  169. [media release];
  170. [cachedTime release];
  171. [super dealloc];
  172. }
  173. - (void)setDelegate:(id)value
  174. {
  175. delegate = value;
  176. }
  177. - (id)delegate
  178. {
  179. return delegate;
  180. }
  181. - (void)setVideoView:(VLCVideoView *)aVideoView
  182. {
  183. [self setDrawable: aVideoView];
  184. }
  185. - (void)setVideoLayer:(VLCVideoLayer *)aVideoLayer
  186. {
  187. [self setDrawable: aVideoLayer];
  188. }
  189. - (void)setDrawable:(id)aDrawable
  190. {
  191. // Make sure that this instance has been associated with the drawing canvas.
  192. libvlc_exception_t ex;
  193. libvlc_exception_init( &ex );
  194. libvlc_media_player_set_nsobject(instance, aDrawable, &ex);
  195. catch_exception( &ex );
  196. }
  197. - (id)drawable
  198. {
  199. libvlc_exception_t ex;
  200. libvlc_exception_init( &ex );
  201. id ret = libvlc_media_player_get_nsobject(instance);
  202. catch_exception( &ex );
  203. return ret;
  204. }
  205. - (VLCAudio *)audio
  206. {
  207. return [[VLCLibrary sharedLibrary] audio];
  208. }
  209. - (void)setVideoAspectRatio:(char *)value
  210. {
  211. libvlc_video_set_aspect_ratio( instance, value, NULL );
  212. }
  213. - (char *)videoAspectRatio
  214. {
  215. libvlc_exception_t ex;
  216. libvlc_exception_init( &ex );
  217. char * result = libvlc_video_get_aspect_ratio( instance, &ex );
  218. catch_exception( &ex );
  219. return result;
  220. }
  221. - (void)setVideoSubTitles:(int)value
  222. {
  223. libvlc_video_set_spu( instance, value, NULL );
  224. }
  225. - (int)videoSubTitles
  226. {
  227. libvlc_exception_t ex;
  228. libvlc_exception_init( &ex );
  229. int result = libvlc_video_get_spu( instance, &ex );
  230. catch_exception( &ex );
  231. return result;
  232. }
  233. - (void)setVideoCropGeometry:(char *)value
  234. {
  235. libvlc_video_set_crop_geometry( instance, value, NULL );
  236. }
  237. - (char *)videoCropGeometry
  238. {
  239. libvlc_exception_t ex;
  240. libvlc_exception_init( &ex );
  241. char * result = libvlc_video_get_crop_geometry( instance, &ex );
  242. catch_exception( &ex );
  243. return result;
  244. }
  245. - (void)setVideoTeleText:(int)value
  246. {
  247. libvlc_video_set_teletext( instance, value, NULL );
  248. }
  249. - (int)videoTeleText
  250. {
  251. libvlc_exception_t ex;
  252. libvlc_exception_init( &ex );
  253. int result = libvlc_video_get_teletext( instance, &ex );
  254. catch_exception( &ex );
  255. return result;
  256. }
  257. - (void)setRate:(float)value
  258. {
  259. libvlc_media_player_set_rate( instance, value, NULL );
  260. }
  261. - (float)rate
  262. {
  263. libvlc_exception_t ex;
  264. libvlc_exception_init( &ex );
  265. float result = libvlc_media_player_get_rate( instance, &ex );
  266. catch_exception( &ex );
  267. return result;
  268. }
  269. - (NSSize)videoSize
  270. {
  271. libvlc_exception_t ex;
  272. libvlc_exception_init( &ex );
  273. NSSize result = NSMakeSize(libvlc_video_get_height((libvlc_media_player_t *)instance, &ex),
  274. libvlc_video_get_width((libvlc_media_player_t *)instance, &ex));
  275. catch_exception( &ex );
  276. return result;
  277. }
  278. - (BOOL)hasVideoOut
  279. {
  280. libvlc_exception_t ex;
  281. libvlc_exception_init( &ex );
  282. BOOL result = libvlc_media_player_has_vout((libvlc_media_player_t *)instance, &ex);
  283. if (libvlc_exception_raised( &ex ))
  284. {
  285. libvlc_exception_clear( &ex );
  286. return NO;
  287. }
  288. else
  289. return result;
  290. }
  291. - (float)framesPerSecond
  292. {
  293. libvlc_exception_t ex;
  294. libvlc_exception_init( &ex );
  295. float result = libvlc_media_player_get_fps( (libvlc_media_player_t *)instance, &ex );
  296. catch_exception( &ex );
  297. return result;
  298. }
  299. - (void)setTime:(VLCTime *)value
  300. {
  301. libvlc_exception_t ex;
  302. libvlc_exception_init( &ex );
  303. // Time is managed in seconds, while duration is managed in microseconds
  304. // TODO: Redo VLCTime to provide value numberAsMilliseconds, numberAsMicroseconds, numberAsSeconds, numberAsMinutes, numberAsHours
  305. libvlc_media_player_set_time( (libvlc_media_player_t *)instance,
  306. (value ? [[value numberValue] longLongValue] / 1000 : 0),
  307. &ex );
  308. catch_exception( &ex );
  309. }
  310. - (VLCTime *)time
  311. {
  312. return cachedTime;
  313. }
  314. - (void)setChapter:(int)value;
  315. {
  316. libvlc_media_player_set_chapter( instance, value, NULL );
  317. }
  318. - (int)chapter
  319. {
  320. libvlc_exception_t ex;
  321. libvlc_exception_init( &ex );
  322. int result = libvlc_media_player_get_chapter( instance, &ex );
  323. catch_exception( &ex );
  324. return result;
  325. }
  326. - (int)countOfChapters
  327. {
  328. libvlc_exception_t ex;
  329. libvlc_exception_init( &ex );
  330. int result = libvlc_media_player_get_chapter_count( instance, &ex );
  331. catch_exception( &ex );
  332. return result;
  333. }
  334. - (void)setAudioTrack:(int)value
  335. {
  336. libvlc_audio_set_track( instance, value, NULL );
  337. }
  338. - (int)audioTrack
  339. {
  340. libvlc_exception_t ex;
  341. libvlc_exception_init( &ex );
  342. int result = libvlc_audio_get_track( instance, &ex );
  343. catch_exception( &ex );
  344. return result;
  345. }
  346. - (int)countOfAudioTracks
  347. {
  348. libvlc_exception_t ex;
  349. libvlc_exception_init( &ex );
  350. int result = libvlc_audio_get_track_count( instance, &ex );
  351. catch_exception( &ex );
  352. return result;
  353. }
  354. - (void)setAudioChannel:(int)value
  355. {
  356. libvlc_audio_set_channel( instance, value, NULL );
  357. }
  358. - (int)audioChannel
  359. {
  360. libvlc_exception_t ex;
  361. libvlc_exception_init( &ex );
  362. int result = libvlc_audio_get_channel( instance, &ex );
  363. catch_exception( &ex );
  364. return result;
  365. }
  366. - (void)setMedia:(VLCMedia *)value
  367. {
  368. if (media != value)
  369. {
  370. if (media && [media compare:value] == NSOrderedSame)
  371. return;
  372. [media release];
  373. media = [value retain];
  374. libvlc_exception_t ex;
  375. libvlc_exception_init( &ex );
  376. libvlc_media_player_set_media( instance, [media libVLCMediaDescriptor], &ex );
  377. catch_exception( &ex );
  378. }
  379. }
  380. - (VLCMedia *)media
  381. {
  382. return media;
  383. }
  384. - (BOOL)play
  385. {
  386. libvlc_exception_t ex;
  387. libvlc_exception_init( &ex );
  388. libvlc_media_player_play( (libvlc_media_player_t *)instance, &ex );
  389. catch_exception( &ex );
  390. return YES;
  391. }
  392. - (void)pause
  393. {
  394. if( [NSThread isMainThread] )
  395. {
  396. /* Hack because we create a dead lock here, when the vout is stopped
  397. * and tries to recontact us on the main thread */
  398. /* FIXME: to do this properly we need to do some locking. We may want
  399. * to move that to libvlc */
  400. [self performSelectorInBackground:@selector(pause) withObject:nil];
  401. return;
  402. }
  403. // Pause the stream
  404. libvlc_exception_t ex;
  405. libvlc_exception_init( &ex );
  406. libvlc_media_player_pause( (libvlc_media_player_t *)instance, &ex );
  407. catch_exception( &ex );
  408. }
  409. - (void)stop
  410. {
  411. if( 0 && [NSThread isMainThread] )
  412. {
  413. /* Hack because we create a dead lock here, when the vout is stopped
  414. * and tries to recontact us on the main thread */
  415. /* FIXME: to do this properly we need to do some locking. We may want
  416. * to move that to libvlc */
  417. [self performSelectorInBackground:@selector(stop) withObject:nil];
  418. return;
  419. }
  420. libvlc_exception_t ex;
  421. libvlc_exception_init( &ex );
  422. libvlc_media_player_stop((libvlc_media_player_t *)instance, &ex);
  423. catch_exception( &ex );
  424. }
  425. - (void)fastForward
  426. {
  427. [self fastForwardAtRate: 2.0];
  428. }
  429. - (void)fastForwardAtRate:(float)rate
  430. {
  431. [self setRate:rate];
  432. }
  433. - (void)rewind
  434. {
  435. [self rewindAtRate: 2.0];
  436. }
  437. - (void)rewindAtRate:(float)rate
  438. {
  439. [self setRate: -rate];
  440. }
  441. + (NSSet *)keyPathsForValuesAffectingIsPlaying
  442. {
  443. return [NSSet setWithObjects:@"state", nil];
  444. }
  445. - (BOOL)isPlaying
  446. {
  447. VLCMediaPlayerState state = [self state];
  448. return ((state == VLCMediaPlayerStateOpening) || (state == VLCMediaPlayerStateBuffering) ||
  449. (state == VLCMediaPlayerStatePlaying));
  450. }
  451. - (BOOL)willPlay
  452. {
  453. libvlc_exception_t ex;
  454. libvlc_exception_init( &ex );
  455. BOOL ret = libvlc_media_player_will_play( (libvlc_media_player_t *)instance, &ex );
  456. if (libvlc_exception_raised(&ex))
  457. {
  458. libvlc_exception_clear(&ex);
  459. return NO;
  460. }
  461. else
  462. return ret;
  463. }
  464. static const VLCMediaPlayerState libvlc_to_local_state[] =
  465. {
  466. [libvlc_Stopped] = VLCMediaPlayerStateStopped,
  467. [libvlc_Opening] = VLCMediaPlayerStateOpening,
  468. [libvlc_Buffering] = VLCMediaPlayerStateBuffering,
  469. [libvlc_Playing] = VLCMediaPlayerStatePlaying,
  470. [libvlc_Paused] = VLCMediaPlayerStatePaused,
  471. [libvlc_Ended] = VLCMediaPlayerStateEnded,
  472. [libvlc_Error] = VLCMediaPlayerStateError
  473. };
  474. - (VLCMediaPlayerState)state
  475. {
  476. return cachedState;
  477. }
  478. - (float)position
  479. {
  480. return position;
  481. }
  482. - (void)setPosition:(float)newPosition
  483. {
  484. libvlc_exception_t ex;
  485. libvlc_exception_init( &ex );
  486. libvlc_media_player_set_position( instance, newPosition, &ex );
  487. catch_exception( &ex );
  488. }
  489. - (BOOL)isSeekable
  490. {
  491. libvlc_exception_t ex;
  492. libvlc_exception_init( &ex );
  493. BOOL ret = libvlc_media_player_is_seekable( instance, &ex );
  494. catch_exception( &ex );
  495. return ret;
  496. }
  497. - (BOOL)canPause
  498. {
  499. libvlc_exception_t ex;
  500. libvlc_exception_init( &ex );
  501. BOOL ret = libvlc_media_player_can_pause( instance, &ex );
  502. catch_exception( &ex );
  503. return ret;
  504. }
  505. - (void *)libVLCMediaPlayer
  506. {
  507. return instance;
  508. }
  509. @end
  510. @implementation VLCMediaPlayer (Private)
  511. - (id)initWithDrawable:(id)aDrawable
  512. {
  513. if (self = [super init])
  514. {
  515. delegate = nil;
  516. media = nil;
  517. cachedTime = [[VLCTime nullTime] retain];
  518. position = 0.0f;
  519. cachedState = VLCMediaPlayerStateStopped;
  520. // Create a media instance, it doesn't matter what library we start off with
  521. // it will change depending on the media descriptor provided to the media
  522. // instance
  523. libvlc_exception_t ex;
  524. libvlc_exception_init( &ex );
  525. instance = (void *)libvlc_media_player_new([VLCLibrary sharedInstance], &ex);
  526. catch_exception( &ex );
  527. [self registerObservers];
  528. [self setDrawable:aDrawable];
  529. }
  530. return self;
  531. }
  532. - (void)registerObservers
  533. {
  534. libvlc_exception_t ex;
  535. libvlc_exception_init( &ex );
  536. // Attach event observers into the media instance
  537. libvlc_event_manager_t * p_em = libvlc_media_player_event_manager( instance, &ex );
  538. libvlc_event_attach( p_em, libvlc_MediaPlayerPlaying, HandleMediaInstanceStateChanged, self, &ex );
  539. libvlc_event_attach( p_em, libvlc_MediaPlayerPaused, HandleMediaInstanceStateChanged, self, &ex );
  540. libvlc_event_attach( p_em, libvlc_MediaPlayerEncounteredError, HandleMediaInstanceStateChanged, self, &ex );
  541. libvlc_event_attach( p_em, libvlc_MediaPlayerEndReached, HandleMediaInstanceStateChanged, self, &ex );
  542. /* FIXME: We may want to turn that off when none is interested by that */
  543. libvlc_event_attach( p_em, libvlc_MediaPlayerPositionChanged, HandleMediaPositionChanged, self, &ex );
  544. libvlc_event_attach( p_em, libvlc_MediaPlayerTimeChanged, HandleMediaTimeChanged, self, &ex );
  545. catch_exception( &ex );
  546. }
  547. - (void)unregisterObservers
  548. {
  549. libvlc_event_manager_t * p_em = libvlc_media_player_event_manager( instance, NULL );
  550. libvlc_event_detach( p_em, libvlc_MediaPlayerPlaying, HandleMediaInstanceStateChanged, self, NULL );
  551. libvlc_event_detach( p_em, libvlc_MediaPlayerPaused, HandleMediaInstanceStateChanged, self, NULL );
  552. libvlc_event_detach( p_em, libvlc_MediaPlayerEncounteredError, HandleMediaInstanceStateChanged, self, NULL );
  553. libvlc_event_detach( p_em, libvlc_MediaPlayerEndReached, HandleMediaInstanceStateChanged, self, NULL );
  554. libvlc_event_detach( p_em, libvlc_MediaPlayerPositionChanged, HandleMediaPositionChanged, self, NULL );
  555. libvlc_event_detach( p_em, libvlc_MediaPlayerTimeChanged, HandleMediaTimeChanged, self, NULL );
  556. }
  557. - (void)mediaPlayerTimeChanged:(NSNumber *)newTime
  558. {
  559. [self willChangeValueForKey:@"time"];
  560. [cachedTime release];
  561. cachedTime = [[VLCTime timeWithNumber:newTime] retain];
  562. [self didChangeValueForKey:@"time"];
  563. }
  564. - (void)delaySleep
  565. {
  566. UpdateSystemActivity(UsrActivity);
  567. }
  568. - (void)mediaPlayerPositionChanged:(NSNumber *)newPosition
  569. {
  570. // This seems to be the most relevant place to delay sleeping and screen saver.
  571. [self delaySleep];
  572. [self willChangeValueForKey:@"position"];
  573. position = [newPosition floatValue];
  574. [self didChangeValueForKey:@"position"];
  575. }
  576. - (void)mediaPlayerStateChanged:(NSNumber *)newState
  577. {
  578. [self willChangeValueForKey:@"state"];
  579. cachedState = [newState intValue];
  580. [self didChangeValueForKey:@"state"];
  581. }
  582. @end