gpt4 book ai didi

objective-c - VLCKit : VLCMediaPlayerDelegate in a Cocoa Application

转载 作者:搜寻专家 更新时间:2023-10-30 20:05:18 25 4
gpt4 key购买 nike

我正在尝试为 Mac OSX 10.10 开发一个 Cocoa 应用程序,它在 VLCKit 中实现了一些视频流。现在:

  1. 我已经编译了 .framework 库并将其导入到 Xcode 中。
  2. 我在我的 Main.storyboard 中添加了一个Custom View 并将其设置为 VLCVideoView

The View

  1. 在我的 ViewController.h 中,我实现了 VLCMediaPlayerDelegate 以接收来自播放器的通知

这是我的代码:

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. 如何设置委托(delegate)以接收有关当前玩家时间的通知?
  2. 如何阅读 NSNotification? (我不太习惯 Obj-C)

提前感谢您的回答!

最佳答案

我成功了!

  1. 如何设置委托(delegate)以接收有关当前玩家时间的通知?我必须向 NSNotificationCenter 添加一个观察者

代码如下:

- (void)viewDidLoad
{
[super viewDidLoad];

[player setDelegate:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mediaPlayerTimeChanged:) name:VLCMediaPlayerTimeChanged object:nil];
}
  1. 如何读取 NSNotification?我必须在通知中检索 VLCMediaPlayer 对象。

代码:

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

关于objective-c - VLCKit : VLCMediaPlayerDelegate in a Cocoa Application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26769546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com