VLCMediaPlayer.m 20 KB

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