Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <MediaPlayer/MediaPlayer.h>
- #import <UIKit/UIKit.h>
- #import "VideoPlugin.h"
- UISwipeGestureRecognizer * swipe;
- MPMoviePlayerController *player;
- NSURL *url;
- UIWindow *backgroundWindow;
- void UnityPause(bool pause);
- NSString* CreateNSString (const char* string)
- {
- if (string)
- return [NSString stringWithUTF8String: string];
- else
- return [NSString stringWithUTF8String: ""];
- }
- @implementation VideoPlugin
- - (void)loadLevelNative
- {
- UnityPause(false);
- UnitySendMessage("GameObject", "loadLevelUnity", "pictureScroll");
- }
- @end
- // When native code plugin is implemented in .mm / .cpp file, then functions
- // should be surrounded with extern "C" block to conform C function naming rules
- VideoPlugin *swipetarget = [[VideoPlugin alloc] init];
- extern "C" {
- void _playVideo(const char *videoFilepath)
- {
- UnityPause(true);
- url = [NSURL URLWithString:CreateNSString(videoFilepath)];
- player = [[MPMoviePlayerController alloc] initWithContentURL:url];
- player.controlStyle = MPMovieControlStyleFullscreen;
- player.view.transform = CGAffineTransformConcat(player.view.transform,
- CGAffineTransformMakeRotation(M_PI_2));
- backgroundWindow = [[UIApplication sharedApplication] keyWindow];
- [player.view setFrame:backgroundWindow.frame];
- [backgroundWindow addSubview:player.view];
- swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:swipetarget
- action:@selector(loadLevelNative)];
- [swipe setDirection:(UISwipeGestureRecognizerDirectionUp |
- UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft
- |UISwipeGestureRecognizerDirectionRight)];
- [player.view addGestureRecognizer:swipe];
- [player play];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement