Guest User

Untitled

a guest
Jan 13th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. AVPlayer *player = [AVPlayer playerWithURL:fileURL];
  2. AVPlayerViewController *playerViewController = [AVPlayerViewController new];
  3. [player pause];
  4. [player play];
  5. playerViewController.player = player;
  6.  
  7. [self addChildViewController: playerViewController];
  8. [self.view addSubview: playerViewController.view];
  9. //[playerViewController.player play];//Used to Play On start
  10. [self presentViewController:playerViewController animated:YES completion:nil];
  11.  
  12. #import <UIKit/UIKit.h>
  13. #import <AVKit/AVKit.h>
  14.  
  15. @interface ViewController : UIViewController
  16. @property (strong, nonatomic) AVPlayerViewController *playerViewController;
  17. - (IBAction)actionPlayVideo:(id)sender;
  18.  
  19. @end
  20.  
  21. #import "ViewController.h"
  22.  
  23. @interface ViewController (){
  24. NSURL *vedioURL;
  25. }
  26.  
  27. @end
  28.  
  29. @implementation ViewController
  30. @synthesize playerViewController;
  31.  
  32. - (IBAction)actionPlayVideo:(id)sender{
  33. NSString *fullpath = [[self documentsDirectory] stringByAppendingPathComponent:@"yourdate.3gp"];
  34. vedioURL =[NSURL fileURLWithPath:fullpath];
  35. AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:vedioURL];
  36. AVPlayer* playVideo = [[AVPlayer alloc] initWithPlayerItem:playerItem];
  37. playerViewController = [[AVPlayerViewController alloc] init];
  38. playerViewController.player = playVideo;
  39. playerViewController.player.volume = 0;
  40. playerViewController.view.frame = self.view.bounds;
  41. [self.view addSubview:playerViewController.view];
  42. [playVideo play];
  43. }
  44. -(NSString *)documentsDirectory{
  45. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  46. NSString *documentsDirectory = [paths objectAtIndex:0];
  47. return documentsDirectory;
  48. }
  49.  
  50. NSURL *videoURL = [NSURL fileURLWithPath:filePath];
  51. //filePath may be from the Bundle or from the Saved file Directory, it is just the path for the video
  52. AVPlayer *player = [AVPlayer playerWithURL:videoURL];
  53. AVPlayerViewController *playerViewController = [AVPlayerViewController new];
  54. playerViewController.player = player;
  55. //[playerViewController.player play];//Used to Play On start
  56. [self presentViewController:playerViewController animated:YES completion:nil];
  57.  
  58. #import <AVFoundation/AVFoundation.h>
  59. #import <AVKit/AVKit.h>
  60.  
  61. NSString *filepath = [[NSBundle mainBundle] pathForResource:@"08-03-201711:21:67" ofType:@"3gp"];
  62.  
  63. NSURL *fileURL = [NSURL fileURLWithPath:filepath];
  64.  
  65. AVPlayer *player = [AVPlayer playerWithURL:fileURL];
  66. AVPlayerViewController *playerViewController = [AVPlayerViewController new];
  67. [player pause];
  68. [player play];
  69. playerViewController.player = player;
  70.  
  71. [self addChildViewController: playerViewController];
  72. [self.view addSubview: playerViewController.view];
Add Comment
Please, Sign In to add comment