项目介绍:
MD360Player4iOS
It is a lite library to render 360 degree panorama video for iOS.
这是一个精简版的库来呈现360度全景视频 (for iOS)。
Pod 支持cocoapods
pod ‘MD360Player4iOS’, ‘~> 1.0.0’
USAGE 使用说明
[Objective-C] 查看源文件 复制代码
- (void)viewDidLoad { [super viewDidLoad]; // Create a AVPlayerItem AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:self.mURL]; [self.player setPlayerItem:playerItem]; [self.player play]; /////////////////////////////////////////////////////// MDVRLibrary MDVRConfiguration* config = [MDVRLibrary createConfig]; [config asVideo:playerItem]; [config setContainer:self view:self.view]; // optional [config displayMode:MDModeDisplayNormal]; [config interactiveMode:MDModeInteractiveMotion]; [config pinchEnabled:true]; [config setDirectorFactory:self]; self.vrLibrary = [config build]; /////////////////////////////////////////////////////// MDVRLibrary }
Supported Configuration[Objective-C] 查看源文件 复制代码
typedef NS_ENUM(NSInteger, MDModeInteractive) { MDModeInteractiveTouch, MDModeInteractiveMotion, MDModeInteractiveMotionWithTouch, }; typedef NS_ENUM(NSInteger, MDModeDisplay) { MDModeDisplayNormal, MDModeDisplayGlass, };
Enabled Pinch Gesture[Objective-C] 查看源文件 复制代码
/////////////////////////////////////////////////////// MDVRLibrary MDVRConfiguration* config = [MDVRLibrary createConfig]; ... [config pinchEnabled:true]; self.vrLibrary = [config build]; /////////////////////////////////////////////////////// MDVRLibrary
Custom Director Factory[Objective-C] 查看源文件 复制代码
@interface CustomDirectorFactory : NSObject<MD360DirectorFactory> @end @implementation CustomDirectorFactory - (MD360Director*) createDirector:(int) index{ MD360Director* director = [[MD360Director alloc]init]; switch (index) { case 1: [director setEyeX:-2.0f]; [director setLookX:-2.0f]; break; default: break; } return director; } @end @implementation VideoPlayerViewController ... - (void) initPlayer{ ... /////////////////////////////////////////////////////// MDVRLibrary MDVRConfiguration* config = [MDVRLibrary createConfig]; ... [config [[CustomDirectorFactory alloc]init]]; // pass in the custom factory ... self.vrLibrary = [config build]; /////////////////////////////////////////////////////// MDVRLibrary } @end
360 Bitmap Support[Objective-C] 查看源文件 复制代码
@interface BitmapPlayerViewController ()<IMDImageProvider> @end @implementation BitmapPlayerViewController ... - (void) initPlayer{ ... /////////////////////////////////////////////////////// MDVRLibrary MDVRConfiguration* config = [MDVRLibrary createConfig]; ... [config asImage:self]; ... self.vrLibrary = [config build]; /////////////////////////////////////////////////////// MDVRLibrary } // implement the IMDImageProvider protocol here. -(void) onProvideImage:(id<TextureCallback>)callback{ // SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader]; [downloader downloadImageWithURL:self.mURL options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) { NSLog(@"progress:%ld/%ld",receivedSize,expectedSize); // progression tracking code } completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { if ( image && finished) { // do something with image if ([callback respondsToSelector:@selector(texture:)]) { [callback texture:image]; } } }]; } @end
DEMO 直接下载: