首页 > 代码库 > iOS 视频播放器单例类
iOS 视频播放器单例类
#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
@interface XHMoviePlayer : MPMoviePlayerController
-(void)playWithUrl:(NSString *)url;
-(instancetype)init;
+(instancetype)defaultMoviePlayer;
-(void)playWithFilePath:(NSString *)path;
@end
#import "XHMoviePlayer.h"
@implementation XHMoviePlayer
-(instancetype)init
{
if (self == [super init]) {
}
return self;
}
+(instancetype)defaultMoviePlayer
{
static XHMoviePlayer *moviePlayer = nil;
static dispatch_once_t onceTaken;
dispatch_once(&onceTaken, ^{
moviePlayer = [[XHMoviePlayer alloc] init];
});
return moviePlayer;
}
-(void)playWithUrl:(NSString *)url
{
NSURL *Url = [NSURL URLWithString:url];
self.contentURL = Url;
[self play];
}
-(void)playWithFilePath:(NSString *)path
{
NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
self.contentURL = url;
[self play];
}
@end
iOS 视频播放器单例类