1 /*****************************************************************************
2 * VLCMediaListPlayer.m: VLCKit.framework VLCMediaListPlayer implementation
3 *****************************************************************************
4 * Copyright (C) 2009 Pierre d'Herbemont
5 * Partial Copyright (C) 2009 Felix Paul Kühne
6 * Copyright (C) 2009 the VideoLAN team
9 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
10 * Felix Paul Kühne <fkuehne # videolan.org
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 #import "VLCMediaListPlayer.h"
29 #import "VLCMediaPlayer.h"
30 #import "VLCMediaList.h"
31 #import "VLCLibVLCBridging.h"
33 @implementation VLCMediaListPlayer
36 if (self = [super init])
38 _mediaPlayer = [[VLCMediaPlayer alloc] init];
40 libvlc_exception_t ex;
41 libvlc_exception_init(&ex);
42 instance = libvlc_media_list_player_new([VLCLibrary sharedInstance], &ex);
44 libvlc_media_list_player_set_media_player(instance, [_mediaPlayer libVLCMediaPlayer], &ex);
52 libvlc_media_list_player_release(instance);
53 [_mediaPlayer release];
58 - (VLCMediaPlayer *)mediaPlayer
63 - (void)setMediaList:(VLCMediaList *)mediaList
65 if (_mediaList == mediaList)
68 _mediaList = [mediaList retain];
70 libvlc_exception_t ex;
71 libvlc_exception_init(&ex);
72 libvlc_media_list_player_set_media_list(instance, [mediaList libVLCMediaList], &ex);
74 [self willChangeValueForKey:@"rootMedia"];
77 [self didChangeValueForKey:@"rootMedia"];
80 - (VLCMediaList *)mediaList
85 - (void)setRootMedia:(VLCMedia *)media
87 if (_rootMedia == media)
92 VLCMediaList *mediaList = [[VLCMediaList alloc] init];
94 [mediaList addMedia:media];
96 // This will clean rootMedia
97 [self setMediaList:mediaList];
99 // Thus set rootMedia here.
100 _rootMedia = [media retain];
105 - (VLCMedia *)rootMedia
110 - (void)playMedia:(VLCMedia *)media
112 libvlc_exception_t ex;
113 libvlc_exception_init(&ex);
114 libvlc_media_list_player_play_item(instance, [media libVLCMediaDescriptor], &ex);
115 catch_exception(&ex);
120 libvlc_exception_t ex;
121 libvlc_exception_init(&ex);
122 libvlc_media_list_player_play(instance, &ex);
123 catch_exception(&ex);
128 libvlc_exception_t ex;
129 libvlc_exception_init(&ex);
130 libvlc_media_list_player_stop(instance, &ex);
131 catch_exception(&ex);
134 - (void)setRepeatMode:(VLCRepeatMode)repeatMode
136 libvlc_exception_t ex;
137 libvlc_exception_init(&ex);
138 switch (repeatMode) {
139 case VLCRepeatAllItems:
140 libvlc_media_list_player_set_playback_mode(instance, libvlc_playback_mode_default, &ex);
143 libvlc_media_list_player_set_playback_mode(instance, libvlc_playback_mode_default, &ex);
145 case VLCRepeatCurrentItem:
146 libvlc_media_list_player_set_playback_mode(instance, libvlc_playback_mode_repeat, &ex);
151 catch_exception(&ex);
152 _repeatMode = repeatMode;
155 - (VLCRepeatMode)repeatMode