Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

objective c - AVPlayer do not play on macOS

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:

enter image description here

How can I make the video play? Thanks!

question from:https://stackoverflow.com/questions/65839139/avplayer-do-not-play-on-macos

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...