2014-11-06 82 views
3

我正在嘗試爲Mac OSX 10.10開發一個Cocoa應用程序,該應用程序在VLCKit中實現了一些視頻流。 現在:VLCKit:可可應用程序中的VLCMediaPlayerDelegate

  1. 我已經編譯了.framework庫,我已經在Xcode進口它。
  2. 我添加了一個自定義視圖我Main.storyboard並將其設置爲一個VLCVideoView

The View

  • 在我ViewController.h我已經實施了VLCMediaPlayerDelegate以接收來自玩家的通知
  • 她E公司我的代碼:

    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 
    

    視頻啓動和正常播放。但是我無法讓代表工作。 我錯在哪裏?

    這裏是我的問題:

    1. 我怎樣才能設置代理接收關於當前播放時間的通知?
    2. 如何閱讀NSNotification? (我並不是真正習慣Obj-C)

    預先感謝您的任何答案!

    +0

    對於我的第一個問題我已經找到了解決方案!我忘了添加下面這行代碼: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mediaPlayerTimeChanged :) name:VLCMediaPlayerTimeChanged object:nil]; – 2014-11-06 00:21:39

    回答

    3

    我已經管理好了!

    1. 如何設置代表接收有關當前玩家時間的通知?我不得不添加一個觀察員NSNotificationCenter

    下面的代碼:

    - (void)viewDidLoad 
    { 
        [super viewDidLoad]; 
    
        [player setDelegate:self]; 
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mediaPlayerTimeChanged:) name:VLCMediaPlayerTimeChanged object:nil]; 
    } 
    
  • 如何我可以閱讀NSNotification?我不得不檢索通知內的VLCMediaPlayer對象。
  • 代碼:

    - (void)mediaPlayerTimeChanged:(NSNotification *)aNotification 
    { 
        VLCMediaPlayer *player = [aNotification object]; 
        VLCTime *currentTime = player.time; 
    } 
    
    +0

    清晰且有幫助! – 2014-11-07 11:08:03