]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Sources/VLCMediaListPlayer.m
f83af7719a4fa580bf184cfdc6fb828c4c97705e
[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], &ex);
45         catch_exception(&ex);
46     }
47     return self;
48 }
49
50 - (void)dealloc
51 {
52     libvlc_media_list_player_release(instance);
53     [_mediaPlayer release];
54     [_rootMedia release];
55     [_mediaList release];
56     [super dealloc];
57 }
58 - (VLCMediaPlayer *)mediaPlayer
59 {
60     return _mediaPlayer;
61 }
62
63 - (void)setMediaList:(VLCMediaList *)mediaList
64 {
65     if (_mediaList == mediaList)
66         return;
67     [_mediaList release];
68     _mediaList = [mediaList retain];
69     
70     libvlc_exception_t ex;
71     libvlc_exception_init(&ex);
72     libvlc_media_list_player_set_media_list(instance, [mediaList libVLCMediaList], &ex);
73     catch_exception(&ex);
74     [self willChangeValueForKey:@"rootMedia"];
75     [_rootMedia release];
76     _rootMedia = nil;
77     [self didChangeValueForKey:@"rootMedia"];
78 }
79
80 - (VLCMediaList *)mediaList
81 {
82     return _mediaList;
83 }
84
85 - (void)setRootMedia:(VLCMedia *)media
86 {
87     if (_rootMedia == media)
88         return;
89     [_rootMedia release];
90     _rootMedia = nil;
91
92     VLCMediaList *mediaList = [[VLCMediaList alloc] init];
93     if (media)
94         [mediaList addMedia:media];
95
96     // This will clean rootMedia
97     [self setMediaList:mediaList];
98
99     // Thus set rootMedia here.
100     _rootMedia = [media retain];
101
102     [mediaList release];
103 }
104
105 - (VLCMedia *)rootMedia
106 {
107     return _rootMedia;
108 }
109
110 - (void)playMedia:(VLCMedia *)media
111 {
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);
116 }
117
118 - (void)play
119 {
120     libvlc_exception_t ex;
121     libvlc_exception_init(&ex);
122     libvlc_media_list_player_play(instance, &ex);
123     catch_exception(&ex);
124 }
125
126 - (void)stop
127 {
128     libvlc_exception_t ex;
129     libvlc_exception_init(&ex);
130     libvlc_media_list_player_stop(instance, &ex);
131     catch_exception(&ex);
132 }
133
134 - (void)doNotRepeatAnyItem;
135 {
136     libvlc_exception_t ex;
137     libvlc_exception_init(&ex);
138     libvlc_media_list_player_set_playback_mode(instance, libvlc_playback_mode_default, &ex);
139     catch_exception(&ex);
140 }
141
142 - (void)repeatCurrentItem
143 {
144     libvlc_exception_t ex;
145     libvlc_exception_init(&ex);
146     libvlc_media_list_player_set_playback_mode(instance, libvlc_playback_mode_repeat, &ex);
147     catch_exception(&ex);
148 }
149
150 - (void)repeatAllItems
151 {
152     libvlc_exception_t ex;
153     libvlc_exception_init(&ex);
154     libvlc_media_list_player_set_playback_mode(instance, libvlc_playback_mode_loop, &ex);
155     catch_exception(&ex);
156 }
157 @end