I am writing a simple program to play video on macOS. Here is my code:
#import <Cocoa/Cocoa.h>
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreFoundation/CoreFoundation.h>
int main()
{
[NSAutoreleasePool new];
id app = [NSApplication sharedApplication];
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
NSRect frame = NSMakeRect(0, 0, 300, 300);
id window =
[[[NSWindow alloc] initWithContentRect:frame
styleMask:NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO] autorelease];
[window cascadeTopLeftFromPoint:NSMakePoint(10, 10)];
[window setTitle:@"Hello"];
[window makeKeyAndOrderFront:nil];
AVPlayerView *controller = [[[AVPlayerView alloc] initWithFrame:frame] autorelease];
[[window contentView] addSubview:controller];
NSString *str = @"playme.mp4";
NSURL *URL = [NSURL URLWithString:str];
AVPlayer *avplayer = [[AVPlayer alloc] initWithURL:URL];
controller.player = avplayer;
[avplayer play];
[app run];
return 0;
}
But after I run it I can only get this:
How can I make the video play? Thanks!
question from:
https://stackoverflow.com/questions/65839139/avplayer-do-not-play-on-macos 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…