2

I am trying to read a video file saved as a data file in the XCAssets folder of my project. I am using the following code for this -

NSString *videoFilePath = [[NSBundle mainBundle] pathForResource:@"login_video" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:videoFilePath];
self.avPlayer = [AVPlayer playerWithURL: fileURL];
self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;

This code had been working for me for quite sometime with target SDK set to iOS 8. I recently changed to iOS 9, and this now gives me a nil path and url. The resource login_video is stored as a data file in my XCAssets folder. What am I doing wrong here?

Thanks!

Shivam Bhalla
  • 1,879
  • 5
  • 35
  • 63

1 Answers1

2

there are two way to get your url

first if you want useXCAssets

NSDataAsset *ob = [[NSDataAsset alloc]initWithName:@"a"];
   NSData *obdata = ob.data;
  [obdata writeToFile:@"your path" atomically:YES];
NSURL *filepath = [NSURL fileURLWithPath:@"your path"];
AVPlayerItem *player = [AVPlayerItem playerItemWithURL:filepath];

second

copy the video to mainBundle of your project and get it with

NSString *videoFilePath = [[NSBundle mainBundle] pathForResource:@"login_video" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:videoFilePath];

not in XCAssets folder.

balkaran singh
  • 2,754
  • 1
  • 17
  • 32
  • Make sure the assets are members of your target; for some reason I noticed in an app that was failing it wasn't; not sure how but you should see a phase of "Compiling asset catalog" during build. – slashlos Sep 23 '17 at 21:09