Playing a Video on mac and win32

Playing a Video on mac and win32

No idea but atleast you will find solution for win32 in this forum.

1 Like

We have a VideoPlayer class that I believe works on all platforms, but I have never tested it on anything but ios and android:

Thats only for ios and android.

Could you use FFMPEG directly? Although it looks like that might be a bit of work…

Edit: maybe Gstreamer?

Is GStreamer available for platforms other than Linux?

Yes, GStreamer is a cross-platform multimedia framework that works on all major 
operating systems, including but not limited to Linux, Android, iOS, macOS, Windows, 
and *BSD, and there are official SDK binary packages for Android, iOS, macOS and 
Windows made available with every GStreamer release.

I spent a few days on integrating ffmpeg and gave up.

I used to have some code I used to play videos on a few platforms using FFMPEG and libavcodec and libavformat but I’m not sure what drive it is on. Why doesn’t an easier solution exist these days…

I thought the same. there are no easy solution for such a common task. And I couldn’t find any test projects for ffmpeg either.

using Avplayer for Mac is pretty straight forward. But I’m guessing its not that compatible with glfw. I’ll do some research on it tomorrow and i’ll update you if I find something.

Cool, I’d like to know and maybe I can help somehow.

you integrated ffmpeg with cocos2d-x?

no, I wrote the code myself for a tech demo I wrote maybe 5 years ago, just before I started with Cocos officially.

So no one has any idea on how to play a video on mac or windows?

I want to use FFMpeg or libVLC with cocos2d-x.

need some days.

I did manage to play video on both mac and windows. Using AVKit for mac and MediaPlayer for windows.
But I’m not sure if those were the best options.

@yinjimmy wait does this mean you are going to add FFMpeg in sdkbox? :smiley: :smiley: :smiley:

Will not be included in SDKBox, personal development.

If anyone is looking for a solution for mac… This worked for me.

    #include <AVKit/AVKit.h>
   _fileName = videoPath;
    NSWindow* nsWindow = Director::getInstance()->getOpenGLView()->getCocoaWindow();
    NSView* view = nsWindow.contentView;
    NSString *str = [NSString stringWithCString:videoPath.c_str()
                                       encoding:[NSString defaultCStringEncoding]];
    NSURL *videoFileURL = [NSURL fileURLWithPath: str];
    avPlayer = [[AVPlayer alloc] initWithURL:videoFileURL];
    AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer: avPlayer];
    [containerView setWantsLayer:YES];
    playerLayer.frame = view.frame;
    [containerView.layer addSublayer: playerLayer];
    [playerLayer setVideoGravity: AVLayerVideoGravityResizeAspect];
    [playerLayer setNeedsDisplay];
    [containerView needsDisplay];
    [view addSubview:containerView];

And for win32 I used

bilalmirza – Does your Mac code really work? I’m having trouble with it. Given that it’s running in a cocos2d-x scene, where do you get the value for “containerView”?

1 Like


I think i have all the files here.


Before you replied, I answered my own question using this value for containerView:

auto rect = Director::getInstance()->getSafeAreaRect();
auto containerView = [[NSView alloc] initWithFrame: NSMakeRect(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];

1 Like