Commit 8112341a authored by Soomin Lee's avatar Soomin Lee

VLCMediaListPlayer: Add libvlc callbacks

parent 551324db
...@@ -3,11 +3,13 @@ ...@@ -3,11 +3,13 @@
***************************************************************************** *****************************************************************************
* Copyright (C) 2009 Pierre d'Herbemont * Copyright (C) 2009 Pierre d'Herbemont
* Partial Copyright (C) 2009-2013 Felix Paul Kühne * Partial Copyright (C) 2009-2013 Felix Paul Kühne
* Copyright (C) 2009-2013 VLC authors and VideoLAN * Copyright (C) 2009-2019 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org> * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
* Felix Paul Kühne <fkuehne # videolan.org * Felix Paul Kühne <fkuehne # videolan.org>
* Soomin Lee <bubu # mikan.io>
* *
* This program is free software; you can redistribute it and/or modify it * 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 * under the terms of the GNU Lesser General Public License as published by
...@@ -24,7 +26,7 @@ ...@@ -24,7 +26,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
@class VLCMedia, VLCMediaPlayer, VLCMediaList; @class VLCMedia, VLCMediaPlayer, VLCMediaList, VLCMediaListPlayer;
/** /**
* VLCRepeatMode * VLCRepeatMode
...@@ -36,6 +38,27 @@ typedef NS_ENUM(NSInteger, VLCRepeatMode) { ...@@ -36,6 +38,27 @@ typedef NS_ENUM(NSInteger, VLCRepeatMode) {
VLCRepeatAllItems VLCRepeatAllItems
}; };
@protocol VLCMediaListPlayerDelegate <NSObject>
@optional
/**
* Sent when VLCMediaListPlayer has finished playing.
*/
- (void)mediaListPlayerFinishedPlayback:(VLCMediaListPlayer *)player;
/**
* Sent when VLCMediaListPlayer going to play next media
*/
- (void)mediaListPlayer:(VLCMediaListPlayer *)player
nextMedia:(VLCMedia *)media;
/**
* Sent when VLCMediaListPlayer is stopped.
* Internally or by using the stop()
* \see stop
*/
- (void)mediaListPlayerStopped:(VLCMediaListPlayer *)player;
@end
/** /**
* A media list player, which eases the use of playlists * A media list player, which eases the use of playlists
*/ */
...@@ -59,6 +82,11 @@ typedef NS_ENUM(NSInteger, VLCRepeatMode) { ...@@ -59,6 +82,11 @@ typedef NS_ENUM(NSInteger, VLCRepeatMode) {
*/ */
@property (readonly) VLCMediaPlayer *mediaPlayer; @property (readonly) VLCMediaPlayer *mediaPlayer;
/**
* Receiver's delegate
*/
@property (nonatomic, weak) id <VLCMediaListPlayerDelegate> delegate;
/** /**
* initializer with a certain drawable * initializer with a certain drawable
* \note drawable can also be set later * \note drawable can also be set later
......
...@@ -3,11 +3,12 @@ ...@@ -3,11 +3,12 @@
***************************************************************************** *****************************************************************************
* Copyright (C) 2009 Pierre d'Herbemont * Copyright (C) 2009 Pierre d'Herbemont
* Partial Copyright (C) 2009-2017 Felix Paul Kühne * Partial Copyright (C) 2009-2017 Felix Paul Kühne
* Copyright (C) 2009-2013 VLC authors and VideoLAN * Copyright (C) 2009-2019 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org> * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
* Felix Paul Kühne <fkuehne # videolan.org * Felix Paul Kühne <fkuehne # videolan.org>
* Soomin Lee <bubu # mikan.io>
* *
* This program is free software; you can redistribute it and/or modify it * 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 * under the terms of the GNU Lesser General Public License as published by
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
#import "VLCMediaList.h" #import "VLCMediaList.h"
#import "VLCLibVLCBridging.h" #import "VLCLibVLCBridging.h"
#import "VLCLibrary.h" #import "VLCLibrary.h"
#import "VLCEventManager.h"
@interface VLCMediaListPlayer () { @interface VLCMediaListPlayer () {
void *instance; void *instance;
...@@ -41,6 +43,36 @@ ...@@ -41,6 +43,36 @@
} }
@end @end
static void HandleMediaListPlayerPlayed(const libvlc_event_t * event, void * self)
{
@autoreleasepool {
[[VLCEventManager sharedManager] callOnMainThreadObject:(__bridge id)(self)
withMethod:@selector(mediaListPlayerPlayed)
withArgumentAsObject:nil];
}
}
static void HandleMediaListPlayerNextItemSet(const libvlc_event_t * event, void * self)
{
@autoreleasepool {
VLCMedia *media = [[VLCMedia alloc]
initWithLibVLCMediaDescriptor:event->u.media_list_player_next_item_set.item];
[[VLCEventManager sharedManager] callOnMainThreadObject:(__bridge id)(self)
withMethod:@selector(mediaListPlayerNextItemSet:)
withArgumentAsObject:media];
}
}
static void HandleMediaListPlayerStopped(const libvlc_event_t * event, void * self)
{
@autoreleasepool {
[[VLCEventManager sharedManager] callOnMainThreadObject:(__bridge id)(self)
withMethod:@selector(mediaListPlayerStopped)
withArgumentAsObject:nil];
}
}
@implementation VLCMediaListPlayer @implementation VLCMediaListPlayer
- (instancetype)initWithOptions:(NSArray *)options andDrawable:(id)drawable - (instancetype)initWithOptions:(NSArray *)options andDrawable:(id)drawable
...@@ -59,10 +91,46 @@ ...@@ -59,10 +91,46 @@
_mediaPlayer = [[VLCMediaPlayer alloc] initWithLibVLCInstance:libvlc_media_list_player_get_media_player(instance) andLibrary:library]; _mediaPlayer = [[VLCMediaPlayer alloc] initWithLibVLCInstance:libvlc_media_list_player_get_media_player(instance) andLibrary:library];
if (drawable != nil) if (drawable != nil)
[_mediaPlayer setDrawable:drawable]; [_mediaPlayer setDrawable:drawable];
[self registerObservers];
} }
return self; return self;
} }
- (void)registerObservers
{
__block libvlc_event_manager_t * p_em = libvlc_media_list_player_event_manager(instance);
if (!p_em) {
return;
}
dispatch_sync(_libVLCBackgroundQueue,^{
libvlc_event_attach(p_em, libvlc_MediaListPlayerPlayed,
HandleMediaListPlayerPlayed, (__bridge void *)(self));
libvlc_event_attach(p_em, libvlc_MediaListPlayerNextItemSet,
HandleMediaListPlayerNextItemSet, (__bridge void *)(self));
libvlc_event_attach(p_em, libvlc_MediaListPlayerStopped,
HandleMediaListPlayerStopped, (__bridge void *)(self));
});
}
- (void)unregisterObservers
{
libvlc_event_manager_t * p_em = libvlc_media_list_player_event_manager(instance);
if (!p_em) {
return;
}
libvlc_event_detach(p_em, libvlc_MediaListPlayerPlayed,
HandleMediaListPlayerPlayed, (__bridge void *)(self));
libvlc_event_detach(p_em, libvlc_MediaListPlayerNextItemSet,
HandleMediaListPlayerNextItemSet, (__bridge void *)(self));
libvlc_event_detach(p_em, libvlc_MediaListPlayerStopped,
HandleMediaListPlayerStopped, (__bridge void *)(self));
}
- (instancetype)initWithOptions:(NSArray *)options - (instancetype)initWithOptions:(NSArray *)options
{ {
return [self initWithOptions:options andDrawable:nil]; return [self initWithOptions:options andDrawable:nil];
...@@ -81,6 +149,7 @@ ...@@ -81,6 +149,7 @@
- (void)dealloc - (void)dealloc
{ {
[_mediaPlayer stop]; [_mediaPlayer stop];
[self unregisterObservers];
libvlc_media_list_player_release(instance); libvlc_media_list_player_release(instance);
} }
...@@ -205,4 +274,28 @@ ...@@ -205,4 +274,28 @@
{ {
return _repeatMode; return _repeatMode;
} }
#pragma mark - Delegate methods
- (void)mediaListPlayerPlayed
{
if ([_delegate respondsToSelector:@selector(mediaListPlayerPlayed)]) {
[_delegate mediaListPlayerFinishedPlayback:self];
}
}
- (void)mediaListPlayerNextItemSet:(VLCMedia *)media
{
if ([_delegate respondsToSelector:@selector(mediaListPlayer:nextMedia:)]) {
[_delegate mediaListPlayer:self nextMedia:media];
}
}
- (void)mediaListPlayerStopped
{
if ([_delegate respondsToSelector:@selector(mediaListPlayerStopped)]) {
[_delegate mediaListPlayerStopped:self];
}
}
@end @end
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