Commit 276a8f12 authored by Felix Paul Kühne's avatar Felix Paul Kühne

discoverer: add explicit code to start/stop the service without destroying the object

parent 9230ddbf
......@@ -76,9 +76,21 @@
* Initializes new object with specified name.
* \param aServiceName Name of the service for this VLCMediaDiscoverer object.
* \returns Newly created media discoverer.
* \note with VLCKit 3.0 and above, you need to start the discoverer explicitly after creation
*/
- (instancetype)initWithName:(NSString *)aServiceName;
/**
* start media discovery
* \returns -1 if start failed, otherwise 0
*/
- (int)startDiscoverer;
/**
* stop media discovery
*/
- (void)stopDiscoverer;
/**
* a read-only property to retrieve the list of discovered media items
*/
......
......@@ -111,21 +111,15 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t *event, void *user_
libvlc_event_manager_t * p_em = libvlc_media_discoverer_event_manager(_mdis);
libvlc_event_attach(p_em, libvlc_MediaDiscovererStarted, HandleMediaDiscovererStarted, (__bridge void *)(self));
libvlc_event_attach(p_em, libvlc_MediaDiscovererEnded, HandleMediaDiscovererEnded, (__bridge void *)(self));
//FIXME: add more events
int returnValue = libvlc_media_discoverer_start(_mdis);
if (returnValue == -1) {
VKLog(@"media discovery start failed");
return NULL;
}
_running = libvlc_media_discoverer_is_running(_mdis);
}
return self;
}
- (void)dealloc
{
if (_running)
[self stopDiscoverer];
libvlc_event_manager_t *em = libvlc_media_list_event_manager(_mdis);
libvlc_event_detach(em, libvlc_MediaDiscovererStarted, HandleMediaDiscovererStarted, (__bridge void *)(self));
libvlc_event_detach(em, libvlc_MediaDiscovererEnded, HandleMediaDiscovererEnded, (__bridge void *)(self));
......@@ -136,6 +130,23 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t *event, void *user_
libvlc_release(_privateLibrary.instance);
}
- (int)startDiscoverer
{
int returnValue = libvlc_media_discoverer_start(_mdis);
if (returnValue == -1)
VKLog(@"media discovery start failed");
_running = libvlc_media_discoverer_is_running(_mdis);
return returnValue;
}
- (void)stopDiscoverer
{
libvlc_media_discoverer_stop(_mdis);
_running = libvlc_media_discoverer_is_running(_mdis);
}
- (VLCMediaList *)discoveredMedia
{
if (_discoveredMedia)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment