]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Sources/VLCMediaListPlayer.m
5ff85255a28ab123dbb8147722119229fe4d73ce
[vlc] / projects / macosx / framework / Sources / VLCMediaListPlayer.m
1 //
2 //  VLCMediaListPlayer.m
3 //  VLCKit
4 //
5 //  Created by Pierre d'Herbemont on 8/24/09.
6 //  Copyright 2009 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "VLCMediaListPlayer.h"
10 #import "VLCMedia.h"
11 #import "VLCMediaPlayer.h"
12 #import "VLCMediaList.h"
13 #import "VLCLibVLCBridging.h"
14
15 @implementation VLCMediaListPlayer
16 - (id)init
17 {
18     if (self = [super init])
19     {
20         _mediaPlayer = [[VLCMediaPlayer alloc] init];
21
22         libvlc_exception_t ex;
23         libvlc_exception_init(&ex);
24         instance = libvlc_media_list_player_new([VLCLibrary sharedInstance], &ex);
25         catch_exception(&ex);
26         libvlc_media_list_player_set_media_player(instance, [_mediaPlayer libVLCMediaPlayer], &ex);
27         catch_exception(&ex);
28     }
29     return self;
30 }
31
32 - (void)dealloc
33 {
34     libvlc_media_list_player_release(instance);
35     [_mediaPlayer release];
36     [_rootMedia release];
37     [_mediaList release];
38     [super dealloc];
39 }
40 - (VLCMediaPlayer *)mediaPlayer
41 {
42     return _mediaPlayer;
43 }
44
45 - (void)setMediaList:(VLCMediaList *)mediaList
46 {
47     if (_mediaList == mediaList)
48         return;
49     [_mediaList release];
50     _mediaList = [mediaList retain];
51     
52     libvlc_exception_t ex;
53     libvlc_exception_init(&ex);
54     libvlc_media_list_player_set_media_list(instance, [mediaList libVLCMediaList], &ex);
55     catch_exception(&ex);
56     [self willChangeValueForKey:@"rootMedia"];
57     [_rootMedia release];
58     _rootMedia = nil;
59     [self didChangeValueForKey:@"rootMedia"];
60 }
61
62 - (VLCMediaList *)mediaList
63 {
64     return _mediaList;
65 }
66
67 - (void)setRootMedia:(VLCMedia *)media
68 {
69     if (_rootMedia == media)
70         return;
71     [_rootMedia release];
72     _rootMedia = nil;
73
74     VLCMediaList *mediaList = [[VLCMediaList alloc] init];
75     if (media)
76         [mediaList addMedia:media];
77
78     // This will clean rootMedia
79     [self setMediaList:mediaList];
80
81     // Thus set rootMedia here.
82     _rootMedia = [media retain];
83
84     [mediaList release];
85 }
86
87 - (VLCMedia *)rootMedia
88 {
89     return _rootMedia;
90 }
91
92 - (void)playMedia:(VLCMedia *)media
93 {
94     libvlc_exception_t ex;
95     libvlc_exception_init(&ex);
96     libvlc_media_list_player_play_item(instance, [media libVLCMediaDescriptor], &ex);
97     catch_exception(&ex);    
98 }
99
100 - (void)play
101 {
102     libvlc_exception_t ex;
103     libvlc_exception_init(&ex);
104     libvlc_media_list_player_play(instance, &ex);
105     catch_exception(&ex);    
106 }
107
108 - (void)stop
109 {
110     libvlc_exception_t ex;
111     libvlc_exception_init(&ex);
112     libvlc_media_list_player_stop(instance, &ex);
113     catch_exception(&ex);        
114 }
115 @end