Skip to content
Browse files

Class like AVPlayerView, but suitable for older OSes (back to 10.7, w…

…here we first got AVFoundation), and without the annoying playback overlays.
  • Loading branch information...
1 parent 33a47c5 commit c413be1ce57624843ca87279b3aab8dff730bc21 @uliwitness committed Jan 9, 2014
Showing with 68 additions and 0 deletions.
  1. +17 −0 ULIInvisiblePlayerView.h
  2. +51 −0 ULIInvisiblePlayerView.m
View
17 ULIInvisiblePlayerView.h
@@ -0,0 +1,17 @@
+//
+// ULIInvisiblePlayerView.h
+// ObjectCanvas
+//
+// Created by Uli Kusterer on 2013-12-28.
+// Copyright (c) 2013 Uli Kusterer. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#import <AVFoundation/AVFoundation.h>
+
+
+@interface ULIInvisiblePlayerView : NSView
+
+@property (retain,nonatomic) AVPlayer* player;
+
+@end
View
51 ULIInvisiblePlayerView.m
@@ -0,0 +1,51 @@
+//
+// ULIInvisiblePlayerView.m
+// ObjectCanvas
+//
+// Created by Uli Kusterer on 2013-12-28.
+// Copyright (c) 2013 Uli Kusterer. All rights reserved.
+//
+
+#import "ULIInvisiblePlayerView.h"
+
+
+@interface ULIInvisiblePlayerView ()
+
+@property (strong) AVPlayerLayer * playerLayer;
+
+@end
+
+
+@implementation ULIInvisiblePlayerView
+
+- (id)initWithFrame:(NSRect)frame
+{
+ self = [super initWithFrame:frame];
+ if (self)
+ {
+ self.wantsLayer = YES;
+ self.layer = [CALayer layer];
+ }
+ return self;
+}
+
+
+-(void) setPlayer: (AVPlayer*)inPlayer
+{
+ if( !self.playerLayer )
+ {
+ self.playerLayer = [AVPlayerLayer playerLayerWithPlayer: inPlayer];
+ [self.playerLayer setFrame: self.layer.bounds];
+ [self.layer addSublayer: self.playerLayer];
+ }
+ else
+ self.playerLayer.player = inPlayer;
+}
+
+
+-(AVPlayer*) player
+{
+ return self.playerLayer.player;
+}
+
+@end

0 comments on commit c413be1

Please sign in to comment.
Something went wrong with that request. Please try again.