Advertisement
Guest User

Untitled

a guest
Jun 6th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1.  
  2. #import <MediaPlayer/MediaPlayer.h>
  3. #import <UIKit/UIKit.h>
  4. #import "VideoPlugin.h"
  5.  
  6.  
  7. UISwipeGestureRecognizer * swipe;
  8. MPMoviePlayerController *player;
  9. NSURL *url;
  10. UIWindow *backgroundWindow;
  11.  
  12. void UnityPause(bool pause);
  13.  
  14.  
  15. NSString* CreateNSString (const char* string)
  16. {
  17.     if (string)
  18.         return [NSString stringWithUTF8String: string];
  19.     else
  20.         return [NSString stringWithUTF8String: ""];
  21. }
  22.  
  23. @implementation VideoPlugin
  24.  
  25. - (void)loadLevelNative
  26. {
  27.    
  28.     UnityPause(false);
  29.  
  30.     UnitySendMessage("GameObject", "loadLevelUnity", "pictureScroll");
  31.  
  32. }
  33.  
  34. @end
  35.  
  36.  
  37.  
  38.  
  39. // When native code plugin is implemented in .mm / .cpp file, then functions
  40. // should be surrounded with extern "C" block to conform C function naming rules
  41.  
  42. VideoPlugin *swipetarget = [[VideoPlugin alloc] init];
  43.  
  44.  
  45. extern "C" {
  46.    
  47.  
  48.    
  49.     void _playVideo(const char *videoFilepath)
  50.     {
  51.      
  52.        
  53.         UnityPause(true);
  54.      
  55.         url = [NSURL URLWithString:CreateNSString(videoFilepath)];
  56.  
  57.         player = [[MPMoviePlayerController alloc] initWithContentURL:url];
  58.        
  59.         player.controlStyle = MPMovieControlStyleFullscreen;
  60.         player.view.transform = CGAffineTransformConcat(player.view.transform,
  61.         CGAffineTransformMakeRotation(M_PI_2));
  62.        
  63.         backgroundWindow = [[UIApplication sharedApplication] keyWindow];
  64.        
  65.         [player.view setFrame:backgroundWindow.frame];
  66.         [backgroundWindow addSubview:player.view];
  67.        
  68.        
  69.        
  70.        swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:swipetarget  
  71.        action:@selector(loadLevelNative)];
  72.        
  73.        [swipe setDirection:(UISwipeGestureRecognizerDirectionUp |
  74.         UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft
  75.        |UISwipeGestureRecognizerDirectionRight)];
  76.        
  77.    
  78.        [player.view addGestureRecognizer:swipe];
  79.    
  80.        [player play];
  81.        
  82.        
  83.      
  84.        
  85.     }
  86.    
  87.    
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement