Just Player is a very simple wrapper for Cocoa AVPlayer. It wrapps complicated usage of AVPlayer. For those who want to use AVPlayer in a super easy way, and tweek in her/his later need.
Assume we declare a 'player' property of type JustPlayer* in our view controller like this:
#import "JustPlayer.h"
#import "JustPlayerLayerView.h"
@interface ViewController ()
@property (nonatomic, strong) JustPlayer *player;
@end self.player = [[JustPlayer alloc] init];When it is ready to play, this block will be called.
Basically we have to call [play:] inside, you can tweek your own.
__weak ViewController *weak = self;
self.player.blkPlayerItemReady = ^(AVPlayerItemStatus
status) {
if (AVPlayerItemStatusReadyToPlay == status) {
[weak.player play];
}
else {
NSLog(@"player item status is %d", status);
}
};On playing, it will fetch next segmant of video asset, and notifies us.
self.player.blkPlayerItemLoadTimeRange = ^(float start, float duration) {
NSLog(@"get range (%.1f, %.1f)", start, duration);
}; [self.player prepareForURL: url];Use storyboard to add a UIView UI object, set it as JustPlayerLayerView class, and make it as an outlet of your view controller, say :
#import "JustPlayerLayerView.h"
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet JustPlayerLayerView *playerLayer;Set the outlet view as the 'display' of JustPlayer:
[self.playerLayer setPlayer: self.player.player];- For complete demo please reference the SamplePlayer project.
- If you want to add Exception Breakpoint, please change its type from 'All' to 'Objective-C', such that the C++ exception throwed by the Audio related framwork can be passed. http://stackoverflow.com/questions/9683547/avaudioplayer-throws-breakpoint-in-debug-mode
JustPlayer is available under the MIT license. See the LICENSE file for more info.