]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Sources/VLCMediaListPlayer.m
macosx/framework: Get rid of VLCMediaListAspect, and remove a bunch of exception.
[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         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_exception_t ex;
106     libvlc_exception_init(&ex);
107     libvlc_media_list_player_play_item(instance, [media libVLCMediaDescriptor], &ex);
108     catch_exception(&ex);
109 }
110
111 - (void)play
112 {
113     libvlc_exception_t ex;
114     libvlc_exception_init(&ex);
115     libvlc_media_list_player_play(instance, &ex);
116     catch_exception(&ex);
117 }
118
119 - (void)stop
120 {
121     libvlc_media_list_player_stop(instance);
122 }
123
124 - (void)setRepeatMode:(VLCRepeatMode)repeatMode
125 {
126     libvlc_playback_mode_t mode;
127     switch (repeatMode) {
128         case VLCRepeatAllItems:
129             mode = libvlc_playback_mode_loop;
130             break;
131         case VLCDoNotRepeat:
132             mode = libvlc_playback_mode_default;
133             break;
134         case VLCRepeatCurrentItem:
135             mode = libvlc_playback_mode_repeat;
136             break;
137         default:
138             NSAssert(0, @"Should not be reached");
139             break;
140     }
141     libvlc_media_list_player_set_playback_mode(instance, mode);
142
143     _repeatMode = repeatMode;
144 }
145
146 - (VLCRepeatMode)repeatMode
147 {
148     return _repeatMode;
149 }
150 @end