1 /*****************************************************************************
2 * VLCVideoView.h: VLC.framework VLCVideoView implementation
3 *****************************************************************************
4 * Copyright (C) 2007 Pierre d'Herbemont
5 * Copyright (C) 2007 the VideoLAN team
8 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #import <VLC/VLCVideoView.h>
26 #import "VLCLibrary.h"
27 #import "VLCEventManager.h"
31 #include <vlc/libvlc.h>
34 NSString * VLCVideoDidChangeVolume = @"VLCVideoDidChangeVolume";
35 NSString * VLCVideoDidChangeTime = @"VLCVideoDidChangeTime";
36 NSString * VLCVideoDidChangeCurrentlyPlayingItem = @"VLCVideoDidChangeCurrentlyPlayingItem";
37 NSString * VLCVideoDidPause = @"VLCVideoDidPause";
38 NSString * VLCVideoDidPlay = @"VLCVideoDidPlay";
39 NSString * VLCVideoDidStop = @"VLCVideoDidStop";
41 static void HandleMediaListPlayerCurrentPlayingItemChanged( const libvlc_event_t * event, void * self )
43 [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject: self
44 withDelegateMethod: @selector(volumeDidChangeCurrentPlayingItem:)
45 withNotificationName: VLCVideoDidChangeCurrentlyPlayingItem];
48 static void HandleMediaListPlayerPaused( const libvlc_event_t * event, void * self )
50 [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject: self
51 withDelegateMethod: @selector(videoDidPause:)
52 withNotificationName: VLCVideoDidPause];
55 static void HandleMediaListPlayerPlayed( const libvlc_event_t * event, void * self )
57 [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject: self
58 withDelegateMethod: @selector(videoDidPlay:)
59 withNotificationName: VLCVideoDidPlay];
62 static void HandleMediaListPlayerStopped( const libvlc_event_t * event, void * self )
64 [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject: self
65 withDelegateMethod: @selector(videoDidStop:)
66 withNotificationName: VLCVideoDidStop];
69 @implementation VLCVideoView
70 - (id)initWithFrame:(NSRect)frameRect
72 if (self = [super initWithFrame: frameRect])
74 libvlc_exception_t p_e;
75 libvlc_exception_init( &p_e );
76 p_mi = libvlc_media_instance_new( [VLCLibrary sharedInstance], &p_e );
77 quit_on_exception( &p_e );
78 p_mlp = libvlc_media_list_player_new( [VLCLibrary sharedInstance], &p_e );
79 quit_on_exception( &p_e );
80 libvlc_media_list_player_set_media_instance( p_mlp, p_mi, &p_e );
81 quit_on_exception( &p_e );
82 libvlc_media_instance_set_drawable( p_mi, (libvlc_drawable_t)self, &p_e );
83 quit_on_exception( &p_e );
85 libvlc_event_manager_t * p_em = libvlc_media_list_event_manager( p_mlp, &p_e );
86 //libvlc_event_attach( p_em, libvlc_MediaListPlayerCurrentPlayingItemChanged, HandleMediaListPlayerCurrentPlayingItemChanged, self, &p_e );
87 //libvlc_event_attach( p_em, libvlc_MediaListPlayerPaused, HandleMediaListPlayerPaused, self, &p_e );
88 //libvlc_event_attach( p_em, libvlc_MediaListPlayerPlayed, HandleMediaListPlayerPlayed, self, &p_e );
89 //libvlc_event_attach( p_em, libvlc_MediaListPlayerStopped, HandleMediaListPlayerStopped, self, &p_e );
90 quit_on_exception( &p_e );
95 [self setStretchesVideo: NO];
96 [self setAutoresizesSubviews: YES];
103 libvlc_media_instance_release( p_mi );
113 - (void)setPlaylist: (VLCPlaylist *)newPlaylist
115 libvlc_exception_t p_e;
116 libvlc_exception_init( &p_e );
121 playlist = [newPlaylist retain];
123 libvlc_media_list_player_set_media_list( p_mlp, [playlist libVLCMediaList], &p_e );
124 quit_on_exception( &p_e );
127 - (VLCPlaylist *)playlist
135 libvlc_exception_t p_e;
136 libvlc_exception_init( &p_e );
137 libvlc_media_list_player_play( p_mlp, &p_e );
138 quit_on_exception( &p_e );
141 - (void)playItemAtIndex:(int) i
143 libvlc_exception_t p_e;
144 libvlc_exception_init( &p_e );
145 libvlc_media_list_player_play_item_at_index( p_mlp, i, &p_e );
146 quit_on_exception( &p_e );
149 - (void)playMedia:(VLCMedia *) media
151 libvlc_exception_t p_e;
152 libvlc_exception_init( &p_e );
153 libvlc_media_list_player_play_item( p_mlp, [media libVLCMediaDescriptor], &p_e );
154 quit_on_exception( &p_e );
159 libvlc_exception_t p_e;
160 libvlc_exception_init( &p_e );
161 //libvlc_media_list_player_pause( p_mlp, &p_e );
162 quit_on_exception( &p_e );
165 - (void)setCurrentTime:(VLCTime *)timeObj
173 //libvlc_media_list_player_is_playing( p_mlp, &p_e );
174 //quit_on_exception( &p_e );
183 - (VLCTime *)currentTime
188 - (id)currentPlaylistItem
193 /* Video output property */
194 - (void)setStretchesVideo:(BOOL)flag
199 - (BOOL)stretchesVideo
205 - (void)enterFullscreen
210 - (void)leaveFullscreen
216 - (void)setDelegate: (id)newDelegate
220 delegate = [newDelegate retain];
229 @implementation VLCVideoView (NSViewSubclass)
230 - (void)drawRect:(NSRect)aRect
233 [[NSColor blackColor] set];
237 - (BOOL)preservesContentDuringLiveResize
247 @interface VLCOpenGLVoutView : NSView
248 /* This is part of the hack to avoid a warning in -[VLCVideoView addVoutSubview:] */
249 - (void)detachFromVout;
252 @implementation VLCVideoView (VLCOpenGLVoutEmbedding)
253 /* This is called by the libvlc module 'macosx' as soon as there is one vout
255 - (void)addVoutSubview:(id)aView
257 if( [[self subviews] count] )
259 /* XXX: This is a hack until core gets fixed */
261 for( i = 0; i < [[self subviews] count]; i++ )
263 [[[self subviews] objectAtIndex: i] detachFromVout];
264 [[[self subviews] objectAtIndex: i] retain];
265 [[[self subviews] objectAtIndex: i] removeFromSuperview];
268 [self addSubview: aView];
269 [aView setFrame: [self bounds]];
270 [aView setAutoresizingMask:NSViewHeightSizable|NSViewWidthSizable];