I'm trying to develop a Cocoa Application for Mac OSX 10.10 that implements some video streaming in VLCKit. Now:
Here's my code:
viewController.h
#import <Cocoa/Cocoa.h>
#import <VLCKit/VLCKit.h>
@interface ViewController : NSViewController<VLCMediaPlayerDelegate>
@property (weak) IBOutlet VLCVideoView *_vlcVideoView;
//delegates
- (void)mediaPlayerTimeChanged:(NSNotification *)aNotification;
@end
viewController.m
#import "ViewController.h"
@implementation ViewController
{
VLCMediaPlayer *player;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[player setDelegate:self];
[self._vlcVideoView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
self._vlcVideoView.fillScreen = YES;
player = [[VLCMediaPlayer alloc] initWithVideoView:self._vlcVideoView];
NSURL *url = [NSURL URLWithString:@"http://MyRemoteUrl.com/video.mp4"];
VLCMedia *movie = [VLCMedia mediaWithURL:url];
[player setMedia:movie];
[player play];
}
- (void)mediaPlayerTimeChanged:(NSNotification *)aNotification
{
//Here I want to retrieve the current video position.
}
@end
The video start and play correctly. However I can't get the delegate to work. Where I am wrong?
Here are my questions:
Thank you in advance for any answer!
I've managed it!
Here's the code:
- (void)viewDidLoad
{
[super viewDidLoad];
[player setDelegate:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mediaPlayerTimeChanged:) name:VLCMediaPlayerTimeChanged object:nil];
}
Code:
- (void)mediaPlayerTimeChanged:(NSNotification *)aNotification
{
VLCMediaPlayer *player = [aNotification object];
VLCTime *currentTime = player.time;
}