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]);
51 libvlc_media_list_player_release(instance);
52 [_mediaPlayer release];
57 - (VLCMediaPlayer *)mediaPlayer
62 - (void)setMediaList:(VLCMediaList *)mediaList
64 if (_mediaList == mediaList)
67 _mediaList = [mediaList retain];
69 libvlc_media_list_player_set_media_list(instance, [mediaList libVLCMediaList]);
70 [self willChangeValueForKey:@"rootMedia"];
73 [self didChangeValueForKey:@"rootMedia"];
76 - (VLCMediaList *)mediaList
81 - (void)setRootMedia:(VLCMedia *)media
83 if (_rootMedia == media)
88 VLCMediaList *mediaList = [[VLCMediaList alloc] init];
90 [mediaList addMedia:media];
92 // This will clean rootMedia
93 [self setMediaList:mediaList];
95 // Thus set rootMedia here.
96 _rootMedia = [media retain];
101 - (VLCMedia *)rootMedia
106 - (void)playMedia:(VLCMedia *)media
108 libvlc_exception_t ex;
109 libvlc_exception_init(&ex);
110 libvlc_media_list_player_play_item(instance, [media libVLCMediaDescriptor], &ex);
111 catch_exception(&ex);
116 libvlc_exception_t ex;
117 libvlc_exception_init(&ex);
118 libvlc_media_list_player_play(instance, &ex);
119 catch_exception(&ex);
124 libvlc_media_list_player_stop(instance);
127 - (void)setRepeatMode:(VLCRepeatMode)repeatMode
129 libvlc_playback_mode_t mode;
130 switch (repeatMode) {
131 case VLCRepeatAllItems:
132 mode = libvlc_playback_mode_loop;
135 mode = libvlc_playback_mode_default;
137 case VLCRepeatCurrentItem:
138 mode = libvlc_playback_mode_repeat;
141 NSAssert(0, @"Should not be reached");
144 libvlc_media_list_player_set_playback_mode(instance, mode);
146 _repeatMode = repeatMode;
149 - (VLCRepeatMode)repeatMode