VLCMediaListPlayer.m 4.23 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * VLCMediaListPlayer.m: VLCKit.framework VLCMediaListPlayer implementation
 *****************************************************************************
 * Copyright (C) 2009 Pierre d'Herbemont
Felix Paul Kühne's avatar
Felix Paul Kühne committed
5 6
 * Partial Copyright (C) 2009-2013 Felix Paul Kühne
 * Copyright (C) 2009-2013 VLC authors and VideoLAN
7 8 9 10 11
 * $Id$
 *
 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
 *          Felix Paul Kühne <fkuehne # videolan.org
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
12 13 14
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
15 16 17 18
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
19 20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
21
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
22 23 24
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25
 *****************************************************************************/
26 27 28 29 30 31 32 33

#import "VLCMediaListPlayer.h"
#import "VLCMedia.h"
#import "VLCMediaPlayer.h"
#import "VLCMediaList.h"
#import "VLCLibVLCBridging.h"

@implementation VLCMediaListPlayer
34 35

- (id)initWithOptions:(NSArray *)options
36
{
37 38 39
        if (self = [super init]) {
            _mediaPlayer = [[VLCMediaPlayer alloc] initWithOptions:options];

40
            instance = libvlc_media_list_player_new([_mediaPlayer.libraryInstance instance]);
41 42 43 44 45
            libvlc_media_list_player_set_media_player(instance, [_mediaPlayer libVLCMediaPlayer]);
        }
        return self;

}
46

47 48 49
- (id)init
{
    return [self initWithOptions:nil];
50 51 52 53
}

- (void)dealloc
{
54
    [_mediaPlayer stop];
55
    libvlc_media_list_player_release(instance);
56 57
    [_mediaPlayer release];
    [_rootMedia release];
58
    [_mediaList release];
59 60
    [super dealloc];
}
61

62 63 64 65 66 67 68 69 70 71 72
- (VLCMediaPlayer *)mediaPlayer
{
    return _mediaPlayer;
}

- (void)setMediaList:(VLCMediaList *)mediaList
{
    if (_mediaList == mediaList)
        return;
    [_mediaList release];
    _mediaList = [mediaList retain];
73 74

    libvlc_media_list_player_set_media_list(instance, [mediaList libVLCMediaList]);
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    [self willChangeValueForKey:@"rootMedia"];
    [_rootMedia release];
    _rootMedia = nil;
    [self didChangeValueForKey:@"rootMedia"];
}

- (VLCMediaList *)mediaList
{
    return _mediaList;
}

- (void)setRootMedia:(VLCMedia *)media
{
    if (_rootMedia == media)
        return;
    [_rootMedia release];
91 92
    _rootMedia = nil;

93 94 95
    VLCMediaList *mediaList = [[VLCMediaList alloc] init];
    if (media)
        [mediaList addMedia:media];
96 97

    // This will clean rootMedia
98
    [self setMediaList:mediaList];
99 100 101 102

    // Thus set rootMedia here.
    _rootMedia = [media retain];

103 104 105 106 107 108 109 110
    [mediaList release];
}

- (VLCMedia *)rootMedia
{
    return _rootMedia;
}

111 112
- (void)playMedia:(VLCMedia *)media
{
113
    libvlc_media_list_player_play_item(instance, [media libVLCMediaDescriptor]);
114 115
}

116 117
- (void)play
{
118
    libvlc_media_list_player_play(instance);
119 120
}

121 122 123 124 125
- (void)pause
{
    libvlc_media_list_player_pause(instance);
}

126 127
- (void)stop
{
128
    libvlc_media_list_player_stop(instance);
129 130
}

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
- (int)next
{
    return libvlc_media_list_player_next(instance);
}

- (int)previous
{
    return libvlc_media_list_player_previous(instance);
}

- (int)playItemAtIndex:(int)index
{
    return libvlc_media_list_player_play_item_at_index(instance, index);
}

146
- (void)setRepeatMode:(VLCRepeatMode)repeatMode
147
{
148
    libvlc_playback_mode_t mode;
149 150
    switch (repeatMode) {
        case VLCRepeatAllItems:
151
            mode = libvlc_playback_mode_loop;
152 153
            break;
        case VLCDoNotRepeat:
154
            mode = libvlc_playback_mode_default;
155 156
            break;
        case VLCRepeatCurrentItem:
157
            mode = libvlc_playback_mode_repeat;
158 159
            break;
        default:
160
            NSAssert(0, @"Should not be reached");
161 162
            break;
    }
163 164
    libvlc_media_list_player_set_playback_mode(instance, mode);

165
    _repeatMode = repeatMode;
166 167
}

168
- (VLCRepeatMode)repeatMode
169
{
170
    return _repeatMode;
171 172
}
@end