]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Sources/VLCMediaPlayer.m
osx/framework: added wrapper methods for snapshots and deinterlacing
[vlc] / projects / macosx / framework / Sources / VLCMediaPlayer.m
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
26 #import "VLCLibrary.h"
27 #import "VLCMediaPlayer.h"
28 #import "VLCEventManager.h"
29 #import "VLCLibVLCBridging.h"
30 #import "VLCVideoView.h"
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 /* prevent system sleep */
36 #import <CoreServices/CoreServices.h>
37 /* FIXME: Ugly hack! */
38 #ifdef __x86_64__
39 #import <CoreServices/../Frameworks/OSServices.framework/Headers/Power.h>
40 #endif
41
42 #include <vlc/vlc.h>
43
44 /* Notification Messages */
45 NSString * VLCMediaPlayerTimeChanged    = @"VLCMediaPlayerTimeChanged";
46 NSString * VLCMediaPlayerStateChanged   = @"VLCMediaPlayerStateChanged";
47
48 NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state)
49 {
50     static NSString * stateToStrings[] = {
51         [VLCMediaPlayerStateStopped]      = @"VLCMediaPlayerStateStopped",
52         [VLCMediaPlayerStateOpening]      = @"VLCMediaPlayerStateOpening",
53         [VLCMediaPlayerStateBuffering]    = @"VLCMediaPlayerStateBuffering",
54         [VLCMediaPlayerStateEnded]        = @"VLCMediaPlayerStateEnded",
55         [VLCMediaPlayerStateError]        = @"VLCMediaPlayerStateError",
56         [VLCMediaPlayerStatePlaying]      = @"VLCMediaPlayerStatePlaying",
57         [VLCMediaPlayerStatePaused]       = @"VLCMediaPlayerStatePaused"
58     };
59     return stateToStrings[state];
60 }
61
62 /* libvlc event callback */
63 static void HandleMediaInstanceVolumeChanged(const libvlc_event_t * event, void * self)
64 {
65     [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self
66                                                    withDelegateMethod:@selector(mediaPlayerVolumeChanged:)
67                                                  withNotificationName:VLCMediaPlayerVolumeChanged];
68 }
69
70 static void HandleMediaTimeChanged(const libvlc_event_t * event, void * self)
71 {
72     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
73     [[VLCEventManager sharedManager] callOnMainThreadObject:self 
74                                                  withMethod:@selector(mediaPlayerTimeChanged:) 
75                                        withArgumentAsObject:[NSNumber numberWithLongLong:event->u.media_player_time_changed.new_time]];
76
77     [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self
78                                                    withDelegateMethod:@selector(mediaPlayerTimeChanged:)
79                                                  withNotificationName:VLCMediaPlayerTimeChanged];
80     [pool release];
81 }
82
83 static void HandleMediaPositionChanged(const libvlc_event_t * event, void * self)
84 {
85     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
86
87     [[VLCEventManager sharedManager] callOnMainThreadObject:self 
88                                                  withMethod:@selector(mediaPlayerPositionChanged:) 
89                                        withArgumentAsObject:[NSNumber numberWithFloat:event->u.media_player_position_changed.new_position]];
90     [pool release];
91 }
92
93 static void HandleMediaInstanceStateChanged(const libvlc_event_t * event, void * self)
94 {
95     VLCMediaPlayerState newState;
96
97     if( event->type == libvlc_MediaPlayerPlaying )
98         newState = VLCMediaPlayerStatePlaying;
99     else if( event->type == libvlc_MediaPlayerPaused )
100         newState = VLCMediaPlayerStatePaused;
101     else if( event->type == libvlc_MediaPlayerEndReached )
102         newState = VLCMediaPlayerStateStopped;
103     else if( event->type == libvlc_MediaPlayerEncounteredError )
104         newState = VLCMediaPlayerStateError;
105     else
106     {
107         NSLog(@"%s: Unknown event", __FUNCTION__);
108         return;
109     }
110
111     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
112
113     [[VLCEventManager sharedManager] callOnMainThreadObject:self 
114                                                  withMethod:@selector(mediaPlayerStateChanged:) 
115                                        withArgumentAsObject:[NSNumber numberWithInt:newState]];
116
117     [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self
118                                                    withDelegateMethod:@selector(mediaPlayerStateChanged:)
119                                                  withNotificationName:VLCMediaPlayerStateChanged];
120
121     [pool release];
122
123 }
124
125
126 // TODO: Documentation
127 @interface VLCMediaPlayer (Private)
128 - (id)initWithDrawable:(id)aDrawable;
129
130 - (void)registerObservers;
131 - (void)unregisterObservers;
132 - (void)mediaPlayerTimeChanged:(NSNumber *)newTime;
133 - (void)mediaPlayerPositionChanged:(NSNumber *)newTime;
134 - (void)mediaPlayerStateChanged:(NSNumber *)newState;
135 @end
136
137 @implementation VLCMediaPlayer
138
139 /* Bindings */
140 + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key
141 {
142     static NSDictionary * dict = nil;
143     NSSet * superKeyPaths;
144     if( !dict )
145     {
146         dict = [[NSDictionary dictionaryWithObjectsAndKeys:
147             [NSSet setWithObject:@"state"], @"playing",
148             [NSSet setWithObjects:@"state", @"media", nil], @"seekable",
149             [NSSet setWithObjects:@"state", @"media", nil], @"canPause",
150             [NSSet setWithObjects:@"state", @"media", nil], @"description",
151             nil] retain];
152     }
153     if( (superKeyPaths = [super keyPathsForValuesAffectingValueForKey: key]) )
154     {
155         NSMutableSet * ret = [NSMutableSet setWithSet:[dict objectForKey: key]];
156         [ret unionSet:superKeyPaths];
157         return ret;
158     }
159     return [dict objectForKey: key];
160 }
161
162 /* Contructor */
163 - (id)init
164 {
165     return [self initWithDrawable:nil];
166 }
167
168 - (id)initWithVideoView:(VLCVideoView *)aVideoView
169 {
170     return [self initWithDrawable: aVideoView];
171 }
172
173 - (id)initWithVideoLayer:(VLCVideoLayer *)aVideoLayer
174 {
175     return [self initWithDrawable: aVideoLayer];
176 }
177
178 - (void)release
179 {
180     @synchronized(self)
181     {
182         if([self retainCount] <= 1)
183         {
184             /* We must make sure we won't receive new event after an upcoming dealloc
185              * We also may receive a -retain in some event callback that may occcur
186              * Before libvlc_event_detach. So this can't happen in dealloc */
187             [self unregisterObservers];
188         }
189         [super release];
190     }
191 }
192
193 - (void)dealloc
194 {
195     // Always get rid of the delegate first so we can stop sending messages to it
196     // TODO: Should we tell the delegate that we're shutting down?
197     delegate = nil;
198
199     libvlc_media_player_release((libvlc_media_player_t *)instance);
200     
201     // Get rid of everything else
202     [media release];
203     [cachedTime release];
204
205     [super dealloc];
206 }
207
208 - (void)setDelegate:(id)value
209 {
210     delegate = value;
211 }
212
213 - (id)delegate
214 {
215     return delegate;
216 }
217
218 - (void)setVideoView:(VLCVideoView *)aVideoView
219 {    
220     [self setDrawable: aVideoView];
221 }
222
223 - (void)setVideoLayer:(VLCVideoLayer *)aVideoLayer
224 {
225     [self setDrawable: aVideoLayer];
226 }
227
228 - (void)setDrawable:(id)aDrawable
229 {
230     // Make sure that this instance has been associated with the drawing canvas.
231     libvlc_exception_t ex;
232     libvlc_exception_init( &ex );
233     libvlc_media_player_set_nsobject(instance, aDrawable, &ex);
234     catch_exception( &ex );
235 }
236
237 - (id)drawable
238 {
239     libvlc_exception_t ex;
240     libvlc_exception_init( &ex );
241     id ret = libvlc_media_player_get_nsobject(instance);
242     catch_exception( &ex );
243     return ret;
244 }
245
246 - (VLCAudio *)audio
247 {
248     return [[VLCLibrary sharedLibrary] audio];
249 }
250
251 - (void)setVideoAspectRatio:(char *)value
252 {
253     libvlc_video_set_aspect_ratio( instance, value, NULL );
254 }
255
256 - (char *)videoAspectRatio
257 {
258     libvlc_exception_t ex;
259     libvlc_exception_init( &ex );
260     char * result = libvlc_video_get_aspect_ratio( instance, &ex );
261     catch_exception( &ex );
262     return result;
263 }
264
265 - (void)setVideoSubTitles:(int)value
266 {
267     libvlc_video_set_spu( instance, value, NULL );
268 }
269
270 - (int)videoSubTitles
271 {
272     libvlc_exception_t ex;
273     libvlc_exception_init( &ex );
274     int result = libvlc_video_get_spu( instance, &ex );
275     catch_exception( &ex );
276     return result;
277 }
278
279 - (void)setVideoCropGeometry:(char *)value
280 {
281     libvlc_video_set_crop_geometry( instance, value, NULL );
282 }
283
284 - (char *)videoCropGeometry
285 {
286     libvlc_exception_t ex;
287     libvlc_exception_init( &ex );
288     char * result = libvlc_video_get_crop_geometry( instance, &ex );
289     catch_exception( &ex );
290     return result;
291 }
292
293 - (void)setVideoTeleText:(int)value
294 {
295     libvlc_video_set_teletext( instance, value, NULL );
296 }
297
298 - (int)videoTeleText
299 {
300     libvlc_exception_t ex;
301     libvlc_exception_init( &ex );
302     int result = libvlc_video_get_teletext( instance, &ex );
303     catch_exception( &ex );
304     return result;
305 }
306
307 - (void)saveVideoSnapshotAt: (NSString *)path withWidth:(NSUInteger)width andHeight:(NSUInteger)height
308 {
309     libvlc_exception_t ex;
310     libvlc_exception_init( &ex );
311     libvlc_video_take_snapshot( instance, [path UTF8String], width, height, &ex );
312     catch_exception( &ex );
313 }
314
315 - (void)setDeinterlaceFilter: (NSString *)name enabled: (BOOL)enabled
316 {
317     libvlc_exception_t ex;
318     libvlc_exception_init( &ex );
319     libvlc_video_set_deinterlace( instance, (int)enabled , [name UTF8String], &ex );
320     catch_exception( &ex );
321 }
322
323 - (void)setRate:(float)value
324 {
325     libvlc_media_player_set_rate( instance, value, NULL );
326 }
327
328 - (float)rate
329 {
330     libvlc_exception_t ex;
331     libvlc_exception_init( &ex );
332     float result = libvlc_media_player_get_rate( instance, &ex );
333     catch_exception( &ex );
334     return result;
335 }
336
337 - (NSSize)videoSize
338 {
339     libvlc_exception_t ex;
340     libvlc_exception_init( &ex );
341     NSSize result = NSMakeSize(libvlc_video_get_height((libvlc_media_player_t *)instance, &ex),
342                                libvlc_video_get_width((libvlc_media_player_t *)instance, &ex));
343     catch_exception( &ex );
344     return result;
345 }
346
347 - (BOOL)hasVideoOut
348 {
349     libvlc_exception_t ex;
350     libvlc_exception_init( &ex );
351     BOOL result = libvlc_media_player_has_vout((libvlc_media_player_t *)instance, &ex);
352     if (libvlc_exception_raised( &ex ))
353     {
354         libvlc_exception_clear( &ex );
355         return NO;
356     }
357     else
358         return result;
359 }
360
361 - (float)framesPerSecond
362 {
363     libvlc_exception_t ex;
364     libvlc_exception_init( &ex );
365     float result = libvlc_media_player_get_fps( (libvlc_media_player_t *)instance, &ex );
366     catch_exception( &ex );
367     return result;
368 }
369
370 - (void)setTime:(VLCTime *)value
371 {
372     libvlc_exception_t ex;
373     libvlc_exception_init( &ex );
374     // Time is managed in seconds, while duration is managed in microseconds
375     // TODO: Redo VLCTime to provide value numberAsMilliseconds, numberAsMicroseconds, numberAsSeconds, numberAsMinutes, numberAsHours
376     libvlc_media_player_set_time( (libvlc_media_player_t *)instance, 
377                                     (value ? [[value numberValue] longLongValue] / 1000 : 0),
378                                     &ex );
379     catch_exception( &ex );
380 }
381
382 - (VLCTime *)time
383 {
384     return cachedTime;
385 }
386
387 - (void)setChapter:(int)value;
388 {
389     libvlc_media_player_set_chapter( instance, value, NULL );
390 }
391
392 - (int)chapter
393 {
394     libvlc_exception_t ex;
395     libvlc_exception_init( &ex );
396     int result = libvlc_media_player_get_chapter( instance, &ex );
397     catch_exception( &ex );
398     return result;
399 }
400
401 - (int)countOfChapters
402 {
403     libvlc_exception_t ex;
404     libvlc_exception_init( &ex );
405     int result = libvlc_media_player_get_chapter_count( instance, &ex );
406     catch_exception( &ex );
407     return result;
408 }
409
410 - (void)setAudioTrack:(int)value
411 {
412     libvlc_audio_set_track( instance, value, NULL );
413 }
414
415 - (int)audioTrack
416 {
417     libvlc_exception_t ex;
418     libvlc_exception_init( &ex );
419     int result = libvlc_audio_get_track( instance, &ex );
420     catch_exception( &ex );
421     return result;
422 }
423
424 - (int)countOfAudioTracks
425 {
426     libvlc_exception_t ex;
427     libvlc_exception_init( &ex );
428     int result = libvlc_audio_get_track_count( instance, &ex );
429     catch_exception( &ex );
430     return result;
431 }
432
433 - (void)setAudioChannel:(int)value
434 {
435     libvlc_audio_set_channel( instance, value, NULL );
436 }
437
438 - (int)audioChannel
439 {
440     libvlc_exception_t ex;
441     libvlc_exception_init( &ex );
442     int result = libvlc_audio_get_channel( instance, &ex );
443     catch_exception( &ex );
444     return result;
445 }
446
447 - (void)setMedia:(VLCMedia *)value
448 {
449     if (media != value)
450     {
451         if (media && [media compare:value] == NSOrderedSame)
452             return;
453         
454         [media release];
455         media = [value retain];
456
457         libvlc_exception_t ex;
458         libvlc_exception_init( &ex );
459         libvlc_media_player_set_media( instance, [media libVLCMediaDescriptor], &ex );
460         catch_exception( &ex );
461     }
462 }
463
464 - (VLCMedia *)media
465 {
466     return media;
467 }
468
469 - (BOOL)play
470 {    
471     libvlc_exception_t ex;
472     libvlc_exception_init( &ex );
473     libvlc_media_player_play( (libvlc_media_player_t *)instance, &ex );
474     catch_exception( &ex );
475     return YES;
476 }
477
478 - (void)pause
479 {
480     if( [NSThread isMainThread] )
481     {
482         /* Hack because we create a dead lock here, when the vout is stopped
483          * and tries to recontact us on the main thread */
484         /* FIXME: to do this properly we need to do some locking. We may want 
485          * to move that to libvlc */
486         [self performSelectorInBackground:@selector(pause) withObject:nil];
487         return;
488     }
489
490     // Pause the stream
491     libvlc_exception_t ex;
492     libvlc_exception_init( &ex );
493     libvlc_media_player_pause( (libvlc_media_player_t *)instance, &ex );
494     catch_exception( &ex );
495 }
496
497 - (void)stop
498 {
499     if( 0 && [NSThread isMainThread] )
500     {
501         /* Hack because we create a dead lock here, when the vout is stopped
502          * and tries to recontact us on the main thread */
503         /* FIXME: to do this properly we need to do some locking. We may want 
504          * to move that to libvlc */
505         [self performSelectorInBackground:@selector(stop) withObject:nil];
506         return;
507     }
508     
509     libvlc_exception_t ex;
510     libvlc_exception_init( &ex );
511     libvlc_media_player_stop((libvlc_media_player_t *)instance, &ex);
512     catch_exception( &ex );
513 }
514
515 - (void)fastForward
516 {
517     [self fastForwardAtRate: 2.0];
518 }
519
520 - (void)fastForwardAtRate:(float)rate
521 {
522     [self setRate:rate];
523 }
524
525 - (void)rewind
526 {
527     [self rewindAtRate: 2.0];
528 }
529
530 - (void)rewindAtRate:(float)rate
531 {
532     [self setRate: -rate];
533 }
534
535 - (void)jumpBackward:(NSInteger)interval
536 {
537     if( [self isSeekable] )
538     {
539         interval = interval * 1000000;
540         [self setTime: [VLCTime timeWithInt: ([[self time] intValue] - interval)]];
541     }
542 }
543
544 - (void)jumpForward:(NSInteger)interval
545 {
546     if( [self isSeekable] )
547     {
548         interval = interval * 1000000;
549         [self setTime: [VLCTime timeWithInt: ([[self time] intValue] + interval)]];
550     }
551 }
552
553 - (void)extraShortJumpBackward
554 {
555     [self jumpBackward:3];
556 }
557
558 - (void)extraShortJumpForward
559 {
560     [self jumpForward:3];
561 }
562
563 - (void)shortJumpBackward
564 {
565     [self jumpBackward:10];
566 }
567
568 - (void)shortJumpForward
569 {
570     [self jumpForward:10];
571 }
572
573 - (void)mediumJumpBackward
574 {
575     [self jumpBackward:60];
576 }
577
578 - (void)mediumJumpForward
579 {
580     [self jumpForward:60];
581 }
582
583 - (void)longJumpBackward
584 {
585     [self jumpBackward:300];
586 }
587
588 - (void)longJumpForward
589 {
590     [self jumpForward:300];
591 }
592
593 + (NSSet *)keyPathsForValuesAffectingIsPlaying
594 {
595     return [NSSet setWithObjects:@"state", nil];
596 }
597
598 - (BOOL)isPlaying
599 {
600     VLCMediaPlayerState state = [self state];
601     return ((state == VLCMediaPlayerStateOpening) || (state == VLCMediaPlayerStateBuffering) ||
602             (state == VLCMediaPlayerStatePlaying));
603 }
604
605 - (BOOL)willPlay
606 {
607     libvlc_exception_t ex;
608     libvlc_exception_init( &ex );
609     BOOL ret = libvlc_media_player_will_play( (libvlc_media_player_t *)instance, &ex );
610     if (libvlc_exception_raised(&ex))
611     {
612         libvlc_exception_clear(&ex);
613         return NO;
614     }
615     else
616         return ret;
617 }
618
619 static const VLCMediaPlayerState libvlc_to_local_state[] =
620 {
621     [libvlc_Stopped]    = VLCMediaPlayerStateStopped,
622     [libvlc_Opening]    = VLCMediaPlayerStateOpening,
623     [libvlc_Buffering]  = VLCMediaPlayerStateBuffering,
624     [libvlc_Playing]    = VLCMediaPlayerStatePlaying,
625     [libvlc_Paused]     = VLCMediaPlayerStatePaused,
626     [libvlc_Ended]      = VLCMediaPlayerStateEnded,
627     [libvlc_Error]      = VLCMediaPlayerStateError
628 };
629
630 - (VLCMediaPlayerState)state
631 {
632     return cachedState;
633 }
634
635 - (float)position
636 {
637     return position;
638 }
639
640 - (void)setPosition:(float)newPosition
641 {
642     libvlc_exception_t ex;
643     libvlc_exception_init( &ex );
644     libvlc_media_player_set_position( instance, newPosition, &ex );
645     catch_exception( &ex );
646 }
647
648 - (BOOL)isSeekable
649 {
650     libvlc_exception_t ex;
651     libvlc_exception_init( &ex );
652     BOOL ret = libvlc_media_player_is_seekable( instance, &ex );
653     catch_exception( &ex );
654     return ret;
655 }
656
657 - (BOOL)canPause
658 {
659     libvlc_exception_t ex;
660     libvlc_exception_init( &ex );
661     BOOL ret = libvlc_media_player_can_pause( instance, &ex );
662     catch_exception( &ex );
663     return ret;
664 }
665
666 - (void *)libVLCMediaPlayer
667 {
668     return instance;
669 }
670 @end
671
672 @implementation VLCMediaPlayer (Private)
673 - (id)initWithDrawable:(id)aDrawable
674 {
675     if (self = [super init])
676     {
677         delegate = nil;
678         media = nil;
679         cachedTime = [[VLCTime nullTime] retain];
680         position = 0.0f;
681         cachedState = VLCMediaPlayerStateStopped;
682
683         // Create a media instance, it doesn't matter what library we start off with
684         // it will change depending on the media descriptor provided to the media
685         // instance
686         libvlc_exception_t ex;
687         libvlc_exception_init( &ex );
688         instance = (void *)libvlc_media_player_new([VLCLibrary sharedInstance], &ex);
689         catch_exception( &ex );
690         
691         [self registerObservers];
692         
693         [self setDrawable:aDrawable];
694     }
695     return self;
696 }
697
698 - (void)registerObservers
699 {
700     libvlc_exception_t ex;
701     libvlc_exception_init( &ex );
702
703     // Attach event observers into the media instance
704     libvlc_event_manager_t * p_em = libvlc_media_player_event_manager( instance, &ex );
705     libvlc_event_attach( p_em, libvlc_MediaPlayerPlaying,          HandleMediaInstanceStateChanged, self, &ex );
706     libvlc_event_attach( p_em, libvlc_MediaPlayerPaused,           HandleMediaInstanceStateChanged, self, &ex );
707     libvlc_event_attach( p_em, libvlc_MediaPlayerEncounteredError, HandleMediaInstanceStateChanged, self, &ex );
708     libvlc_event_attach( p_em, libvlc_MediaPlayerEndReached,       HandleMediaInstanceStateChanged, self, &ex );
709     /* FIXME: We may want to turn that off when none is interested by that */
710     libvlc_event_attach( p_em, libvlc_MediaPlayerPositionChanged, HandleMediaPositionChanged,      self, &ex );
711     libvlc_event_attach( p_em, libvlc_MediaPlayerTimeChanged,     HandleMediaTimeChanged,          self, &ex );
712     catch_exception( &ex );
713 }
714
715 - (void)unregisterObservers
716 {
717     libvlc_event_manager_t * p_em = libvlc_media_player_event_manager( instance, NULL );
718     libvlc_event_detach( p_em, libvlc_MediaPlayerPlaying,          HandleMediaInstanceStateChanged, self, NULL );
719     libvlc_event_detach( p_em, libvlc_MediaPlayerPaused,           HandleMediaInstanceStateChanged, self, NULL );
720     libvlc_event_detach( p_em, libvlc_MediaPlayerEncounteredError, HandleMediaInstanceStateChanged, self, NULL );
721     libvlc_event_detach( p_em, libvlc_MediaPlayerEndReached,       HandleMediaInstanceStateChanged, self, NULL );
722     libvlc_event_detach( p_em, libvlc_MediaPlayerPositionChanged,  HandleMediaPositionChanged,      self, NULL );
723     libvlc_event_detach( p_em, libvlc_MediaPlayerTimeChanged,      HandleMediaTimeChanged,          self, NULL );
724 }
725
726 - (void)mediaPlayerTimeChanged:(NSNumber *)newTime
727 {
728     [self willChangeValueForKey:@"time"];
729     [cachedTime release];
730     cachedTime = [[VLCTime timeWithNumber:newTime] retain];
731
732     [self didChangeValueForKey:@"time"];
733 }
734
735 - (void)delaySleep
736 {
737     UpdateSystemActivity(UsrActivity);
738 }
739
740 - (void)mediaPlayerPositionChanged:(NSNumber *)newPosition
741 {
742     // This seems to be the most relevant place to delay sleeping and screen saver.
743     [self delaySleep];
744
745     [self willChangeValueForKey:@"position"];
746     position = [newPosition floatValue];
747     [self didChangeValueForKey:@"position"];
748 }
749
750 - (void)mediaPlayerStateChanged:(NSNumber *)newState
751 {
752     [self willChangeValueForKey:@"state"];
753     cachedState = [newState intValue];
754     [self didChangeValueForKey:@"state"];
755 }
756
757 @end