]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Sources/VLCMediaListPlayer.m
Relicense VLCKit to LGPL
[vlc] / projects / macosx / framework / Sources / VLCMediaListPlayer.m
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 VLC authors and VideoLAN
7  * $Id$
8  *
9  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
10  *          Felix Paul Kühne <fkuehne # videolan.org
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU Lesser General Public License as published by
14  * the Free Software Foundation; either version 2.1 of the License, or
15  * (at your option) any later version.
16  *
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 Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this program; if not, write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 #import "VLCMediaListPlayer.h"
28 #import "VLCMedia.h"
29 #import "VLCMediaPlayer.h"
30 #import "VLCMediaList.h"
31 #import "VLCLibVLCBridging.h"
32
33 @implementation VLCMediaListPlayer
34 - (id)init
35 {
36     if (self = [super init])
37     {
38         _mediaPlayer = [[VLCMediaPlayer alloc] init];
39
40         instance = libvlc_media_list_player_new([VLCLibrary sharedInstance]);
41         libvlc_media_list_player_set_media_player(instance, [_mediaPlayer libVLCMediaPlayer]);
42     }
43     return self;
44 }
45
46 - (void)dealloc
47 {
48     libvlc_media_list_player_release(instance);
49     [_mediaPlayer release];
50     [_rootMedia release];
51     [_mediaList release];
52     [super dealloc];
53 }
54 - (VLCMediaPlayer *)mediaPlayer
55 {
56     return _mediaPlayer;
57 }
58
59 - (void)setMediaList:(VLCMediaList *)mediaList
60 {
61     if (_mediaList == mediaList)
62         return;
63     [_mediaList release];
64     _mediaList = [mediaList retain];
65
66     libvlc_media_list_player_set_media_list(instance, [mediaList libVLCMediaList]);
67     [self willChangeValueForKey:@"rootMedia"];
68     [_rootMedia release];
69     _rootMedia = nil;
70     [self didChangeValueForKey:@"rootMedia"];
71 }
72
73 - (VLCMediaList *)mediaList
74 {
75     return _mediaList;
76 }
77
78 - (void)setRootMedia:(VLCMedia *)media
79 {
80     if (_rootMedia == media)
81         return;
82     [_rootMedia release];
83     _rootMedia = nil;
84
85     VLCMediaList *mediaList = [[VLCMediaList alloc] init];
86     if (media)
87         [mediaList addMedia:media];
88
89     // This will clean rootMedia
90     [self setMediaList:mediaList];
91
92     // Thus set rootMedia here.
93     _rootMedia = [media retain];
94
95     [mediaList release];
96 }
97
98 - (VLCMedia *)rootMedia
99 {
100     return _rootMedia;
101 }
102
103 - (void)playMedia:(VLCMedia *)media
104 {
105     libvlc_media_list_player_play_item(instance, [media libVLCMediaDescriptor]);
106 }
107
108 - (void)play
109 {
110     libvlc_media_list_player_play(instance);
111 }
112
113 - (void)stop
114 {
115     libvlc_media_list_player_stop(instance);
116 }
117
118 - (void)setRepeatMode:(VLCRepeatMode)repeatMode
119 {
120     libvlc_playback_mode_t mode;
121     switch (repeatMode) {
122         case VLCRepeatAllItems:
123             mode = libvlc_playback_mode_loop;
124             break;
125         case VLCDoNotRepeat:
126             mode = libvlc_playback_mode_default;
127             break;
128         case VLCRepeatCurrentItem:
129             mode = libvlc_playback_mode_repeat;
130             break;
131         default:
132             NSAssert(0, @"Should not be reached");
133             break;
134     }
135     libvlc_media_list_player_set_playback_mode(instance, mode);
136
137     _repeatMode = repeatMode;
138 }
139
140 - (VLCRepeatMode)repeatMode
141 {
142     return _repeatMode;
143 }
144 @end