VLCMediaPlayer.m 20 KB

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