VLCMediaPlayer.m 20 KB

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