VLCMediaDiscoverer.m 3.35 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*****************************************************************************
 * VLCMediaDiscoverer.m: VLC.framework VLCMediaDiscoverer implementation
 *****************************************************************************
 * Copyright (C) 2007 Pierre d'Herbemont
 * Copyright (C) 2007 the VideoLAN team
 * $Id$
 *
 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (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
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU 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.
 *****************************************************************************/

#import <Cocoa/Cocoa.h>
26
#import "VLCMediaDiscoverer.h"
27
#import "VLCLibrary.h"
28
#import "VLCLibVLCBridging.h"
29
30
31

#include <vlc/libvlc.h>

32
static NSArray * availableMediaDiscoverer = nil;
33
34

@implementation VLCMediaDiscoverer
35
36
37
38
39
40
41
42
43
44
45
46
+ (NSArray *)availableMediaDiscoverer
{
        if( !availableMediaDiscoverer )
        {
            availableMediaDiscoverer = [[NSArray arrayWithObjects:
                                    [[[VLCMediaDiscoverer alloc] initWithName:@"sap"] autorelease],
                                    [[[VLCMediaDiscoverer alloc] initWithName:@"shoutcast"] autorelease],
                                    [[[VLCMediaDiscoverer alloc] initWithName:@"shoutcasttv"] autorelease], nil] retain];
        }
        return availableMediaDiscoverer;
}

47
48
49
50
51
52
53
- (id)initWithName:(NSString *)aServiceName
{
    if (self = [super init])
    {
        libvlc_exception_t ex;
        libvlc_exception_init( &ex );
        localizedName = nil;
54
        discoveredMedia = nil;
55
        mdis = libvlc_media_discoverer_new_from_name( [VLCLibrary sharedInstance],
56
                                                      [aServiceName UTF8String],
57
58
59
60
61
62
63
64
65
66
                                                      &ex );
        quit_on_exception( &ex );       
    }
    return self;
}

- (void)dealloc
{
    if( localizedName )
        [localizedName release];
67
68
    if( discoveredMedia )
        [discoveredMedia release];
69
70
71
72
    libvlc_media_discoverer_release( mdis );
    [super dealloc];
}

73
- (VLCMediaList *) discoveredMedia
74
{
75
76
    if( discoveredMedia )
        return discoveredMedia;
77
78

    libvlc_media_list_t * p_mlist = libvlc_media_discoverer_media_list( mdis );
79
    VLCMediaList * ret = [VLCMediaList mediaListWithLibVLCMediaList: p_mlist];
80
81
82
83
    libvlc_media_list_release( p_mlist );

    if( ret )
    {
84
        discoveredMedia = [ret retain];
85
    }
86
    return discoveredMedia;
87
88
89
90
}

- (NSString *)localizedName
{
91
    NSString * aString = nil;
92
93
94
95
96
97
98
    char * name = libvlc_media_discoverer_localized_name( mdis );

    if( localizedName )
        return localizedName;

    if (name)
    {
99
        aString = [NSString stringWithUTF8String:name];
100
101
        free( name );
    }
102
    if( aString )
103
    {
104
        localizedName = [aString retain];
105
106
107
108
    }
    return localizedName;
}
@end