1 /*****************************************************************************
2 * VLCMediaPlayer.m: VLCKit.framework VLCMediaPlayer implementation
3 *****************************************************************************
4 * Copyright (C) 2007-2009 Pierre d'Herbemont
5 * Copyright (C) 2007-2009 the VideoLAN team
6 * Partial Copyright (C) 2009 Felix Paul Kühne
9 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
10 * Faustion Osuna <enrique.osuna # gmail.com>
11 * Felix Paul Kühne <fkuehne # videolan.org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 #import "VLCLibrary.h"
29 #import "VLCMediaPlayer.h"
30 #import "VLCEventManager.h"
31 #import "VLCLibVLCBridging.h"
32 #import "VLCVideoView.h"
37 /* prevent system sleep */
38 #import <CoreServices/CoreServices.h>
39 /* FIXME: Ugly hack! */
41 #import <CoreServices/../Frameworks/OSServices.framework/Headers/Power.h>
46 /* Notification Messages */
47 NSString * VLCMediaPlayerTimeChanged = @"VLCMediaPlayerTimeChanged";
48 NSString * VLCMediaPlayerStateChanged = @"VLCMediaPlayerStateChanged";
50 NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state)
52 static NSString * stateToStrings[] = {
53 [VLCMediaPlayerStateStopped] = @"VLCMediaPlayerStateStopped",
54 [VLCMediaPlayerStateOpening] = @"VLCMediaPlayerStateOpening",
55 [VLCMediaPlayerStateBuffering] = @"VLCMediaPlayerStateBuffering",
56 [VLCMediaPlayerStateEnded] = @"VLCMediaPlayerStateEnded",
57 [VLCMediaPlayerStateError] = @"VLCMediaPlayerStateError",
58 [VLCMediaPlayerStatePlaying] = @"VLCMediaPlayerStatePlaying",
59 [VLCMediaPlayerStatePaused] = @"VLCMediaPlayerStatePaused"
61 return stateToStrings[state];
64 /* libvlc event callback */
65 static void HandleMediaInstanceVolumeChanged(const libvlc_event_t * event, void * self)
67 [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self
68 withDelegateMethod:@selector(mediaPlayerVolumeChanged:)
69 withNotificationName:VLCMediaPlayerVolumeChanged];
72 static void HandleMediaTimeChanged(const libvlc_event_t * event, void * self)
74 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
75 [[VLCEventManager sharedManager] callOnMainThreadObject:self
76 withMethod:@selector(mediaPlayerTimeChanged:)
77 withArgumentAsObject:[NSNumber numberWithLongLong:event->u.media_player_time_changed.new_time]];
79 [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self
80 withDelegateMethod:@selector(mediaPlayerTimeChanged:)
81 withNotificationName:VLCMediaPlayerTimeChanged];
85 static void HandleMediaPositionChanged(const libvlc_event_t * event, void * self)
87 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
89 [[VLCEventManager sharedManager] callOnMainThreadObject:self
90 withMethod:@selector(mediaPlayerPositionChanged:)
91 withArgumentAsObject:[NSNumber numberWithFloat:event->u.media_player_position_changed.new_position]];
95 static void HandleMediaInstanceStateChanged(const libvlc_event_t * event, void * self)
97 VLCMediaPlayerState newState;
99 if( event->type == libvlc_MediaPlayerPlaying )
100 newState = VLCMediaPlayerStatePlaying;
101 else if( event->type == libvlc_MediaPlayerPaused )
102 newState = VLCMediaPlayerStatePaused;
103 else if( event->type == libvlc_MediaPlayerEndReached )
104 newState = VLCMediaPlayerStateStopped;
105 else if( event->type == libvlc_MediaPlayerEncounteredError )
106 newState = VLCMediaPlayerStateError;
109 NSLog(@"%s: Unknown event", __FUNCTION__);
113 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
115 [[VLCEventManager sharedManager] callOnMainThreadObject:self
116 withMethod:@selector(mediaPlayerStateChanged:)
117 withArgumentAsObject:[NSNumber numberWithInt:newState]];
119 [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self
120 withDelegateMethod:@selector(mediaPlayerStateChanged:)
121 withNotificationName:VLCMediaPlayerStateChanged];
128 // TODO: Documentation
129 @interface VLCMediaPlayer (Private)
130 - (id)initWithDrawable:(id)aDrawable;
132 - (void)registerObservers;
133 - (void)unregisterObservers;
134 - (void)mediaPlayerTimeChanged:(NSNumber *)newTime;
135 - (void)mediaPlayerPositionChanged:(NSNumber *)newTime;
136 - (void)mediaPlayerStateChanged:(NSNumber *)newState;
139 @implementation VLCMediaPlayer
142 + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key
144 static NSDictionary * dict = nil;
145 NSSet * superKeyPaths;
148 dict = [[NSDictionary dictionaryWithObjectsAndKeys:
149 [NSSet setWithObject:@"state"], @"playing",
150 [NSSet setWithObjects:@"state", @"media", nil], @"seekable",
151 [NSSet setWithObjects:@"state", @"media", nil], @"canPause",
152 [NSSet setWithObjects:@"state", @"media", nil], @"description",
155 if( (superKeyPaths = [super keyPathsForValuesAffectingValueForKey: key]) )
157 NSMutableSet * ret = [NSMutableSet setWithSet:[dict objectForKey: key]];
158 [ret unionSet:superKeyPaths];
161 return [dict objectForKey: key];
167 return [self initWithDrawable:nil];
170 - (id)initWithVideoView:(VLCVideoView *)aVideoView
172 return [self initWithDrawable: aVideoView];
175 - (id)initWithVideoLayer:(VLCVideoLayer *)aVideoLayer
177 return [self initWithDrawable: aVideoLayer];
184 if([self retainCount] <= 1)
186 /* We must make sure we won't receive new event after an upcoming dealloc
187 * We also may receive a -retain in some event callback that may occcur
188 * Before libvlc_event_detach. So this can't happen in dealloc */
189 [self unregisterObservers];
197 NSAssert(libvlc_media_player_get_state(instance, NULL) == libvlc_Stopped, @"You released the media player before ensuring that it is stopped");
199 // Always get rid of the delegate first so we can stop sending messages to it
200 // TODO: Should we tell the delegate that we're shutting down?
203 // Clear our drawable as we are going to release it, we don't
204 // want the core to use it from this point. This won't happen as
205 // the media player must be stopped.
206 libvlc_media_player_set_nsobject(instance, nil, NULL);
208 libvlc_media_player_release(instance);
210 // Get rid of everything else
212 [cachedTime release];
218 - (void)setDelegate:(id)value
228 - (void)setVideoView:(VLCVideoView *)aVideoView
230 [self setDrawable: aVideoView];
233 - (void)setVideoLayer:(VLCVideoLayer *)aVideoLayer
235 [self setDrawable: aVideoLayer];
238 - (void)setDrawable:(id)aDrawable
240 // Make sure that this instance has been associated with the drawing canvas.
241 libvlc_exception_t ex;
242 libvlc_exception_init( &ex );
243 libvlc_media_player_set_nsobject(instance, aDrawable, &ex);
244 catch_exception( &ex );
249 libvlc_exception_t ex;
250 libvlc_exception_init( &ex );
251 id ret = libvlc_media_player_get_nsobject(instance);
252 catch_exception( &ex );
258 return [[VLCLibrary sharedLibrary] audio];
262 #pragma mark Subtitles
264 - (void)setCurrentVideoSubTitleIndex:(NSUInteger)index
266 libvlc_exception_t ex;
267 libvlc_exception_init( &ex );
268 libvlc_video_set_spu( instance, (int)index, &ex );
269 catch_exception( &ex );
272 - (NSUInteger)currentVideoSubTitleIndex
274 libvlc_exception_t ex;
275 libvlc_exception_init( &ex );
276 int count = libvlc_video_get_spu_count( instance, &ex );
277 catch_exception( &ex );
280 NSUInteger result = libvlc_video_get_spu( instance, &ex );
281 catch_exception( &ex );
285 - (BOOL)openVideoSubTitlesFromFile:(NSString *)path
287 libvlc_exception_t ex;
288 libvlc_exception_init( &ex );
289 BOOL result = libvlc_video_set_subtitle_file( instance, [path UTF8String], &ex );
290 catch_exception( &ex );
294 - (NSArray *)videoSubTitles
296 libvlc_exception_t ex;
297 libvlc_exception_init( &ex );
298 int count = libvlc_video_get_spu_count( instance, &ex );
299 catch_exception( &ex );
301 libvlc_track_description_t *tracks = libvlc_video_get_spu_description( instance, &ex );
302 NSMutableArray *tempArray = [NSMutableArray array];
304 for (i = 0; i < count; i++)
306 [tempArray addObject:[NSString stringWithUTF8String: tracks->psz_name]];
307 tracks = tracks->p_next;
309 return [NSArray arrayWithArray: tempArray];
314 #pragma mark Video Crop geometry
316 - (void)setVideoCropGeometry:(char *)value
318 libvlc_exception_t ex;
319 libvlc_exception_init( &ex );
320 libvlc_video_set_crop_geometry( instance, value, &ex );
321 catch_exception( &ex );
324 - (char *)videoCropGeometry
326 libvlc_exception_t ex;
327 libvlc_exception_init( &ex );
328 char * result = libvlc_video_get_crop_geometry( instance, &ex );
329 catch_exception( &ex );
333 - (void)setVideoAspectRatio:(char *)value
335 libvlc_exception_t ex;
336 libvlc_exception_init( &ex );
337 libvlc_video_set_aspect_ratio( instance, value, &ex );
338 catch_exception( &ex );
341 - (char *)videoAspectRatio
343 libvlc_exception_t ex;
344 libvlc_exception_init( &ex );
345 char * result = libvlc_video_get_aspect_ratio( instance, &ex );
346 catch_exception( &ex );
350 - (void)setVideoTeleText:(int)value
352 libvlc_exception_t ex;
353 libvlc_exception_init( &ex );
354 libvlc_video_set_teletext( instance, value, &ex );
355 catch_exception( &ex );
360 libvlc_exception_t ex;
361 libvlc_exception_init( &ex );
362 int result = libvlc_video_get_teletext( instance, &ex );
363 catch_exception( &ex );
367 - (void)saveVideoSnapshotAt: (NSString *)path withWidth:(NSUInteger)width andHeight:(NSUInteger)height
369 libvlc_exception_t ex;
370 libvlc_exception_init( &ex );
371 libvlc_video_take_snapshot( instance, [path UTF8String], width, height, &ex );
372 catch_exception( &ex );
375 - (void)setDeinterlaceFilter: (NSString *)name enabled: (BOOL)enabled
377 libvlc_exception_t ex;
378 libvlc_exception_init( &ex );
379 libvlc_video_set_deinterlace( instance, (int)enabled , [name UTF8String], &ex );
380 catch_exception( &ex );
383 - (void)setRate:(float)value
385 libvlc_exception_t ex;
386 libvlc_exception_init( &ex );
387 libvlc_media_player_set_rate( instance, value, &ex );
388 catch_exception( &ex );
393 libvlc_exception_t ex;
394 libvlc_exception_init( &ex );
395 float result = libvlc_media_player_get_rate( instance, &ex );
396 catch_exception( &ex );
402 libvlc_exception_t ex;
403 libvlc_exception_init( &ex );
404 NSSize result = NSMakeSize(libvlc_video_get_height((libvlc_media_player_t *)instance, &ex),
405 libvlc_video_get_width((libvlc_media_player_t *)instance, &ex));
406 catch_exception( &ex );
412 libvlc_exception_t ex;
413 libvlc_exception_init( &ex );
414 BOOL result = libvlc_media_player_has_vout((libvlc_media_player_t *)instance, &ex);
415 if (libvlc_exception_raised( &ex ))
417 libvlc_exception_clear( &ex );
424 - (float)framesPerSecond
426 libvlc_exception_t ex;
427 libvlc_exception_init( &ex );
428 float result = libvlc_media_player_get_fps( (libvlc_media_player_t *)instance, &ex );
429 catch_exception( &ex );
433 - (void)setTime:(VLCTime *)value
435 libvlc_exception_t ex;
436 libvlc_exception_init( &ex );
437 // Time is managed in seconds, while duration is managed in microseconds
438 // TODO: Redo VLCTime to provide value numberAsMilliseconds, numberAsMicroseconds, numberAsSeconds, numberAsMinutes, numberAsHours
439 libvlc_media_player_set_time( (libvlc_media_player_t *)instance,
440 (value ? [[value numberValue] longLongValue] / 1000 : 0),
442 catch_exception( &ex );
450 - (VLCTime *)remainingTime
452 double currentTime = [[cachedTime numberValue] doubleValue];
453 double remaining = currentTime / position * (1 - position);
454 return [VLCTime timeWithNumber:[NSNumber numberWithDouble:-remaining]];
459 libvlc_exception_t ex;
460 libvlc_exception_init( &ex );
461 int result = libvlc_media_player_get_fps( instance, &ex );
462 catch_exception( &ex );
467 #pragma mark Chapters
468 - (void)setCurrentChapterIndex:(NSUInteger)value;
470 libvlc_exception_t ex;
471 libvlc_exception_init( &ex );
472 libvlc_media_player_set_chapter( instance, value, &ex );
473 catch_exception( &ex );
476 - (NSUInteger)currentChapterIndex
478 libvlc_exception_t ex;
479 libvlc_exception_init( &ex );
480 int count = libvlc_media_player_get_chapter_count( instance, &ex );
481 catch_exception( &ex );
484 NSUInteger result = libvlc_media_player_get_chapter( instance, &ex );
485 catch_exception( &ex );
491 libvlc_exception_t ex;
492 libvlc_exception_init( &ex );
493 libvlc_media_player_next_chapter( instance, &ex );
494 catch_exception( &ex );
497 - (void)previousChapter
499 libvlc_exception_t ex;
500 libvlc_exception_init( &ex );
501 libvlc_media_player_previous_chapter( instance, &ex );
502 catch_exception( &ex );
505 - (NSArray *)chaptersForTitleIndex:(NSUInteger)title
507 libvlc_exception_t ex;
508 libvlc_exception_init( &ex );
509 int count = libvlc_media_player_get_chapter_count(instance, &ex);
511 return [NSArray array];
513 libvlc_track_description_t *tracks = libvlc_video_get_chapter_description( instance, title, &ex );
514 NSMutableArray *tempArray = [NSMutableArray array];
516 for (i = 0; i < count ; i++)
518 [tempArray addObject:[NSString stringWithUTF8String: tracks->psz_name]];
519 tracks = tracks->p_next;
521 return [NSArray arrayWithArray: tempArray];
527 - (void)setCurrentTitleIndex:(NSUInteger)value
529 libvlc_exception_t ex;
530 libvlc_exception_init( &ex );
531 libvlc_media_player_set_title( instance, value, &ex );
532 catch_exception( &ex );
535 - (NSUInteger)currentTitleIndex
537 libvlc_exception_t ex;
538 libvlc_exception_init( &ex );
540 int count = libvlc_media_player_get_title_count( instance, &ex );
541 catch_exception( &ex );
545 NSUInteger result = libvlc_media_player_get_title( instance, &ex );
546 catch_exception( &ex );
552 libvlc_exception_t ex;
553 libvlc_exception_init( &ex );
554 int result = libvlc_media_player_get_title_count( instance, &ex );
555 catch_exception( &ex );
561 libvlc_exception_t ex;
562 libvlc_exception_init( &ex );
563 libvlc_track_description_t *tracks = libvlc_video_get_title_description( instance, &ex );
564 NSMutableArray *tempArray = [NSMutableArray array];
566 for (i = 0; i < [self countOfTitles] ; i++)
568 [tempArray addObject:[NSString stringWithUTF8String: tracks->psz_name]];
569 tracks = tracks->p_next;
571 return [NSArray arrayWithArray: tempArray];
575 #pragma mark Audio tracks
576 - (void)setCurrentAudioTrackIndex:(NSUInteger)value
578 libvlc_exception_t ex;
579 libvlc_exception_init( &ex );
580 libvlc_audio_set_track( instance, (int)value, &ex );
581 catch_exception( &ex );
584 - (NSUInteger)currentAudioTrackIndex
586 libvlc_exception_t ex;
587 libvlc_exception_init( &ex );
588 int count = libvlc_audio_get_track_count( instance, &ex );
589 catch_exception( &ex );
593 NSUInteger result = libvlc_audio_get_track( instance, &ex );
594 catch_exception( &ex );
598 - (NSArray *)audioTracks
600 libvlc_exception_t ex;
601 libvlc_exception_init( &ex );
602 int count = libvlc_audio_get_track_count( instance, &ex );
603 catch_exception( &ex );
605 return [NSArray array];
607 libvlc_track_description_t *tracks = libvlc_audio_get_track_description( instance, &ex );
608 NSMutableArray *tempArray = [NSMutableArray array];
610 for (i = 0; i < count ; i++)
612 [tempArray addObject:[NSString stringWithUTF8String: tracks->psz_name]];
613 tracks = tracks->p_next;
616 return [NSArray arrayWithArray: tempArray];
619 - (void)setAudioChannel:(int)value
621 libvlc_exception_t ex;
622 libvlc_exception_init( &ex );
623 libvlc_audio_set_channel( instance, value, &ex );
624 catch_exception( &ex );
629 libvlc_exception_t ex;
630 libvlc_exception_init( &ex );
631 int result = libvlc_audio_get_channel( instance, &ex );
632 catch_exception( &ex );
636 - (void)setMedia:(VLCMedia *)value
640 if (media && [media compare:value] == NSOrderedSame)
644 media = [value retain];
646 libvlc_exception_t ex;
647 libvlc_exception_init( &ex );
648 libvlc_media_player_set_media( instance, [media libVLCMediaDescriptor], &ex );
649 catch_exception( &ex );
660 libvlc_exception_t ex;
661 libvlc_exception_init( &ex );
662 libvlc_media_player_play( (libvlc_media_player_t *)instance, &ex );
663 catch_exception( &ex );
669 if( [NSThread isMainThread] )
671 /* Hack because we create a dead lock here, when the vout is stopped
672 * and tries to recontact us on the main thread */
673 /* FIXME: to do this properly we need to do some locking. We may want
674 * to move that to libvlc */
675 [self performSelectorInBackground:@selector(pause) withObject:nil];
680 libvlc_exception_t ex;
681 libvlc_exception_init( &ex );
682 libvlc_media_player_pause( (libvlc_media_player_t *)instance, &ex );
685 // in most cases, it's just EOF so let's stop
686 if (libvlc_exception_raised(&ex))
689 libvlc_exception_clear(&ex);
694 libvlc_exception_t ex;
695 libvlc_exception_init( &ex );
696 libvlc_media_player_stop((libvlc_media_player_t *)instance, &ex);
697 catch_exception( &ex );
702 [self fastForwardAtRate: 2.0];
705 - (void)fastForwardAtRate:(float)rate
712 [self rewindAtRate: 2.0];
715 - (void)rewindAtRate:(float)rate
717 [self setRate: -rate];
720 - (void)jumpBackward:(NSInteger)interval
722 if( [self isSeekable] )
724 interval = interval * 1000000;
725 [self setTime: [VLCTime timeWithInt: ([[self time] intValue] - interval)]];
729 - (void)jumpForward:(NSInteger)interval
731 if( [self isSeekable] )
733 interval = interval * 1000000;
734 [self setTime: [VLCTime timeWithInt: ([[self time] intValue] + interval)]];
738 - (void)extraShortJumpBackward
740 [self jumpBackward:3];
743 - (void)extraShortJumpForward
745 [self jumpForward:3];
748 - (void)shortJumpBackward
750 [self jumpBackward:10];
753 - (void)shortJumpForward
755 [self jumpForward:10];
758 - (void)mediumJumpBackward
760 [self jumpBackward:60];
763 - (void)mediumJumpForward
765 [self jumpForward:60];
768 - (void)longJumpBackward
770 [self jumpBackward:300];
773 - (void)longJumpForward
775 [self jumpForward:300];
778 + (NSSet *)keyPathsForValuesAffectingIsPlaying
780 return [NSSet setWithObjects:@"state", nil];
785 VLCMediaPlayerState state = [self state];
786 return ((state == VLCMediaPlayerStateOpening) || (state == VLCMediaPlayerStateBuffering) ||
787 (state == VLCMediaPlayerStatePlaying));
792 libvlc_exception_t ex;
793 libvlc_exception_init( &ex );
794 BOOL ret = libvlc_media_player_will_play( (libvlc_media_player_t *)instance, &ex );
795 if (libvlc_exception_raised(&ex))
797 libvlc_exception_clear(&ex);
804 static const VLCMediaPlayerState libvlc_to_local_state[] =
806 [libvlc_Stopped] = VLCMediaPlayerStateStopped,
807 [libvlc_Opening] = VLCMediaPlayerStateOpening,
808 [libvlc_Buffering] = VLCMediaPlayerStateBuffering,
809 [libvlc_Playing] = VLCMediaPlayerStatePlaying,
810 [libvlc_Paused] = VLCMediaPlayerStatePaused,
811 [libvlc_Ended] = VLCMediaPlayerStateEnded,
812 [libvlc_Error] = VLCMediaPlayerStateError
815 - (VLCMediaPlayerState)state
825 - (void)setPosition:(float)newPosition
827 libvlc_exception_t ex;
828 libvlc_exception_init( &ex );
829 libvlc_media_player_set_position( instance, newPosition, &ex );
830 catch_exception( &ex );
835 libvlc_exception_t ex;
836 libvlc_exception_init( &ex );
837 BOOL ret = libvlc_media_player_is_seekable( instance, &ex );
838 catch_exception( &ex );
844 libvlc_exception_t ex;
845 libvlc_exception_init( &ex );
846 BOOL ret = libvlc_media_player_can_pause( instance, &ex );
847 catch_exception( &ex );
851 - (void *)libVLCMediaPlayer
857 @implementation VLCMediaPlayer (Private)
858 - (id)initWithDrawable:(id)aDrawable
860 if (self = [super init])
864 cachedTime = [[VLCTime nullTime] retain];
866 cachedState = VLCMediaPlayerStateStopped;
868 // Create a media instance, it doesn't matter what library we start off with
869 // it will change depending on the media descriptor provided to the media
871 libvlc_exception_t ex;
872 libvlc_exception_init( &ex );
873 instance = (void *)libvlc_media_player_new([VLCLibrary sharedInstance], &ex);
874 catch_exception( &ex );
876 [self registerObservers];
878 [self setDrawable:aDrawable];
883 - (void)registerObservers
885 libvlc_exception_t ex;
886 libvlc_exception_init( &ex );
888 // Attach event observers into the media instance
889 libvlc_event_manager_t * p_em = libvlc_media_player_event_manager( instance, &ex );
890 libvlc_event_attach( p_em, libvlc_MediaPlayerPlaying, HandleMediaInstanceStateChanged, self, &ex );
891 libvlc_event_attach( p_em, libvlc_MediaPlayerPaused, HandleMediaInstanceStateChanged, self, &ex );
892 libvlc_event_attach( p_em, libvlc_MediaPlayerEncounteredError, HandleMediaInstanceStateChanged, self, &ex );
893 libvlc_event_attach( p_em, libvlc_MediaPlayerEndReached, HandleMediaInstanceStateChanged, self, &ex );
894 /* FIXME: We may want to turn that off when none is interested by that */
895 libvlc_event_attach( p_em, libvlc_MediaPlayerPositionChanged, HandleMediaPositionChanged, self, &ex );
896 libvlc_event_attach( p_em, libvlc_MediaPlayerTimeChanged, HandleMediaTimeChanged, self, &ex );
897 catch_exception( &ex );
900 - (void)unregisterObservers
902 libvlc_event_manager_t * p_em = libvlc_media_player_event_manager( instance, NULL );
903 libvlc_event_detach( p_em, libvlc_MediaPlayerPlaying, HandleMediaInstanceStateChanged, self, NULL );
904 libvlc_event_detach( p_em, libvlc_MediaPlayerPaused, HandleMediaInstanceStateChanged, self, NULL );
905 libvlc_event_detach( p_em, libvlc_MediaPlayerEncounteredError, HandleMediaInstanceStateChanged, self, NULL );
906 libvlc_event_detach( p_em, libvlc_MediaPlayerEndReached, HandleMediaInstanceStateChanged, self, NULL );
907 libvlc_event_detach( p_em, libvlc_MediaPlayerPositionChanged, HandleMediaPositionChanged, self, NULL );
908 libvlc_event_detach( p_em, libvlc_MediaPlayerTimeChanged, HandleMediaTimeChanged, self, NULL );
911 - (void)mediaPlayerTimeChanged:(NSNumber *)newTime
913 [self willChangeValueForKey:@"time"];
914 [self willChangeValueForKey:@"remainingTime"];
915 [cachedTime release];
916 cachedTime = [[VLCTime timeWithNumber:newTime] retain];
918 [self didChangeValueForKey:@"remainingTime"];
919 [self didChangeValueForKey:@"time"];
924 UpdateSystemActivity(UsrActivity);
927 - (void)mediaPlayerPositionChanged:(NSNumber *)newPosition
929 // This seems to be the most relevant place to delay sleeping and screen saver.
932 [self willChangeValueForKey:@"position"];
933 position = [newPosition floatValue];
934 [self didChangeValueForKey:@"position"];
937 - (void)mediaPlayerStateChanged:(NSNumber *)newState
939 [self willChangeValueForKey:@"state"];
940 cachedState = [newState intValue];
941 [self didChangeValueForKey:@"state"];