]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Sources/VLCMediaListPlayer.m
278362af3c9014dbcebfe271d1c2dd362932f4b4
[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 the VideoLAN team
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
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.
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 General Public License for more details.
21  *
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  *****************************************************************************/
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         libvlc_exception_t ex;
41         libvlc_exception_init(&ex);
42         instance = libvlc_media_list_player_new([VLCLibrary sharedInstance], &ex);
43         catch_exception(&ex);
44         libvlc_media_list_player_set_media_player(instance, [_mediaPlayer libVLCMediaPlayer]);
45     }
46     return self;
47 }
48
49 - (void)dealloc
50 {
51     libvlc_media_list_player_release(instance);
52     [_mediaPlayer release];
53     [_rootMedia release];
54     [_mediaList release];
55     [super dealloc];
56 }
57 - (VLCMediaPlayer *)mediaPlayer
58 {
59     return _mediaPlayer;
60 }
61
62 - (void)setMediaList:(VLCMediaList *)mediaList
63 {
64     if (_mediaList == mediaList)
65         return;
66     [_mediaList release];
67     _mediaList = [mediaList retain];
68
69     libvlc_media_list_player_set_media_list(instance, [mediaList libVLCMediaList]);
70     [self willChangeValueForKey:@"rootMedia"];
71     [_rootMedia release];
72     _rootMedia = nil;
73     [self didChangeValueForKey:@"rootMedia"];
74 }
75
76 - (VLCMediaList *)mediaList
77 {
78     return _mediaList;
79 }
80
81 - (void)setRootMedia:(VLCMedia *)media
82 {
83     if (_rootMedia == media)
84         return;
85     [_rootMedia release];
86     _rootMedia = nil;
87
88     VLCMediaList *mediaList = [[VLCMediaList alloc] init];
89     if (media)
90         [mediaList addMedia:media];
91
92     // This will clean rootMedia
93     [self setMediaList:mediaList];
94
95     // Thus set rootMedia here.
96     _rootMedia = [media retain];
97
98     [mediaList release];
99 }
100
101 - (VLCMedia *)rootMedia
102 {
103     return _rootMedia;
104 }
105
106 - (void)playMedia:(VLCMedia *)media
107 {
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);
112 }
113
114 - (void)play
115 {
116     libvlc_exception_t ex;
117     libvlc_exception_init(&ex);
118     libvlc_media_list_player_play(instance, &ex);
119     catch_exception(&ex);
120 }
121
122 - (void)stop
123 {
124     libvlc_media_list_player_stop(instance);
125 }
126
127 - (void)setRepeatMode:(VLCRepeatMode)repeatMode
128 {
129     libvlc_playback_mode_t mode;
130     switch (repeatMode) {
131         case VLCRepeatAllItems:
132             mode = libvlc_playback_mode_loop;
133             break;
134         case VLCDoNotRepeat:
135             mode = libvlc_playback_mode_default;
136             break;
137         case VLCRepeatCurrentItem:
138             mode = libvlc_playback_mode_repeat;
139             break;
140         default:
141             NSAssert(0, @"Should not be reached");
142             break;
143     }
144     libvlc_media_list_player_set_playback_mode(instance, mode);
145
146     _repeatMode = repeatMode;
147 }
148
149 - (VLCRepeatMode)repeatMode
150 {
151     return _repeatMode;
152 }
153 @end