25

Can anyone tell me how to add video the iPhone simulator so that I can test some apps I am working on? Thanks in advance!

Rani
  • 2,907
  • 11
  • 46
  • 87
  • 1
    Use MPMoviePlayerController for video playing purpose in iphone. You will find help about it in Apple Documentation. – Mobile Developer iOS Android Jun 16 '11 at 11:50
  • 1
    Just a note: to add a PHOTO easily to the simulator: (1) drag the photo to the simulator (2) note that it opens in SAFARI (3) HOLD DOWN on the photo, then you can save it to the photo.app. In fact **videos work the same way but** you can't play them, it seems. – Fattie Dec 01 '13 at 14:38

9 Answers9

62

It's very simple you just drag any .MOV file to your simulator. Now it will be opened in Safari browser. At top left corner there is a 'Done' button. You just have to press it after this you can press Share button then just choose the option save video and it's done. Now play it in your app. :)

Joshua Dance
  • 6,602
  • 3
  • 52
  • 60
New Coder
  • 723
  • 6
  • 14
  • 9
    You, sir, deserve WAY more up votes. Easiest solution on this page. (Works with XCode 6/iOS 8 Simulator) – Cutetare Aug 23 '14 at 09:34
  • 1
    What the fcuking fcuk! I'm sure Apple must've thought, "Hey that's so intuitive that all iOS devs cant help noticing" – Kedar Paranjape Jul 16 '15 at 10:01
  • Worked also with a mp4 file. I really love you so much right now. I was struggling 1 hour (was about to build a temp download for that). Such a simple solution! BTW, on iOS 9, the video just got saved into the camera roll. Didn't had to do anything. – Hirbod Aug 24 '16 at 01:16
  • Thanks for this! I knew that's how it works and tried with multiple mp4 files. (Maybe they're no longer supported with Xcode 10?) But MOV files worked :) – Alex Wally Dec 07 '18 at 04:47
  • I have tried doing extactly this but is does not work (simulator 11(13.4.1)). the following error comes up: One or more media items failed to import: /Users/me/Downloads/testVid.m4v: The operation couldn’t be completed. (PHPhotosErrorDomain error -1.) – jamesMcKey May 06 '20 at 09:25
  • 2
    Thank-you! When .mov file was dropped on simulator, it went right into Photos. So easy. Confirmed on simulators-> iPhone SE (2nd) (13.4.1) and iPhone 11(13.4.1) – Marcy May 16 '20 at 15:39
  • @jamesMcKey, I dragged an .mp4 (codec H.264) from my desktop onto the iPhone 11 simulator(13.4.1) and it worked. The .mp4 file went immediately into Photos. You might try another file. – Marcy May 16 '20 at 15:48
14

I did the same as you do with images, drag dropped the video onto the iOS simulator not just photo's app but any app can be running on it at the time you drag drop.

Step 1: Drag drop.

enter image description here

Step 2: iOS simulator opens up safari to play the video file.

enter image description here

Step 3: Click on the share icon to get the Save Video option in the action's list.

enter image description here

But clicking on Save Video action for so many times nothing happens and nothing gets added to the albums. Any ideas? Even tried copy pasting the video file to the simulator's DCIM path.

Satheesh
  • 10,292
  • 6
  • 47
  • 89
10

okey, try this:

- (void) downloadVideo {
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://sepwww.stanford.edu/sep/jon/trash/poolwaves.mov"]];

You can change the temp.mov to temp.m4v to save the vid in m4v.

NSString *tempPath = [NSString stringWithFormat:@"%@/temp.mov", NSTemporaryDirectory()];
[imageData writeToFile:tempPath atomically:NO];
UISaveVideoAtPathToSavedPhotosAlbum (tempPath, self, @selector(video:didFinishSavingWithError: contextInfo:), nil);
}


- (void) video: (NSString *) videoPath
didFinishSavingWithError: (NSError *) error
   contextInfo: (void *) contextInfo {
    NSLog(@"Finished saving video with error: %@", error);
}

if you change the url to your moviefile, this should work really well... the movies are saved in this directory: /Library/Application Support/iPhone Simulator/4.3.2/Media/DCIM but you are right, if i copy a file to it, it won't show up in the simulator

greets

Quirin
  • 720
  • 5
  • 10
  • Hi @Schnarchii ,it is not working for me. have copy a .m4v video and pasted in this path ~/Library/Application Support/iPhone Simulator/4.3.2/Media/ – Rani Jun 16 '11 at 12:53
6

Short answer:

  1. Drop your video file into ~/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE/ and maybe delete the PhotoData file in Media.

Long Answer:

  1. Make sure your movie file type is supported on the iPhone. I used a .mov
  2. Open the Library. (YourUserName/Library) If you can't find the file, it is hidden. Make it visible or user Terminal.
  3. Navigate to ~/Library/Application Support/iPhone Simulator/ If you have multiple iOS Simulators pick the one your are developing for currently. (I had 5.0, 5.1, 6.0 and 6.1)
  4. Navigate to ~/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE/ and drop in your video file. If the 100APPLE directory doesn't exist, create it.
  5. Sometimes you have to delete the PhotoData file in Navigate to ~/Library/Application Support/iPhone Simulator/6.1/Media/ to force the Simulator to recognize the new file since you didn't add it through normal means.

Xcode 4.6.3 and MacOS 10.8.4 fyi. Haven't tried on Xcode 5.

Community
  • 1
  • 1
Joshua Dance
  • 6,602
  • 3
  • 52
  • 60
  • i use short answer but i can not find video from Simulator –  Jul 26 '13 at 11:24
  • Try the long answer. :) Did you find the correct files? What version of Xcode and the simulator are you using? – Joshua Dance Jul 26 '13 at 21:53
  • I used both way, but non of this help me to display video in my simulator, my system is ,, `Xcode - 4.6.2 , iOS - 6.1, simulator - 6.0` –  Jul 27 '13 at 04:39
  • Okay .. i got other way for add video in simulator ..http://stackoverflow.com/questions/16455958/how-to-add-videos-in-iphone-6-0-simulator/16456019#16456019 –  Jul 27 '13 at 04:58
  • 1
    Working on Xcode 5.0.2. I needed to delete PhotoData folder like Joshua suggested. – Genki Jan 11 '14 at 18:57
4

You can add Your file by adding these 2 lines of code in appdelegate.m

NSString *path = [[NSBundle mainBundle] pathForResource:@"sample_iTunes" ofType:@"mov"];
UISaveVideoAtPathToSavedPhotosAlbum(path, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);`
swe
  • 83
  • 7
2

go to following path and past video

/Users/"username"/Library/Developer/CoreSimulator/Devices/11BFF1F0-2A2B-409A-9727-3267D71E10D4/data/Media

Sandeep Kumar
  • 318
  • 1
  • 8
0

If you're asking how to add video to your app the simple way to show video using MediaPlayer.h lib.

// fileURL is a NSURL made from file path in app bundle
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL: fileURL];
[[mp view] setFrame:CGRectMake(0,0,100,100)];
[mp play];

You should set many parameters for mp object: scaling, controls, etc.

yosh
  • 3,166
  • 6
  • 52
  • 81
  • i dont want to add video to my app.Initially i want to add it to the iphone simulator to test my app – Rani Jun 16 '11 at 11:43
  • 1
    Where to? There is no "main storage" or SD card on iphone, just apps' documents folders. They're under the paths like /Users/MAC_USER/libraries/application support/iPhone Simulator/4.1/Applications/ – yosh Jun 16 '11 at 11:50
  • OP didn't ask for how to play a video. He is asking how to add a video file to the simulator. This is useful if he is testing a program that needs to use the ImagePicker and his app needs videos instead of photos. – Joshua Dance Jun 27 '13 at 22:38
  • @JoshuaDance He WAS asking it 2 years ago, when iOS was in version 4.1. – yosh Jul 01 '13 at 09:22
  • OP is not asking for "how to add video to your app" he was asking "how to add video the iPhone simulator so that I can test some apps" :) – Joshua Dance Jul 01 '13 at 16:19
0

You need to add video in your application bundle itself. Later you can copy that to the documents directory.

Rahul Vyas
  • 26,593
  • 48
  • 175
  • 252
0

It's been a while... Drag and drop somehow didn't work for me with video file (for both .mov and .mp4). So I adopted obj-c code from one of the answers

let path = Bundle.main.path(forResource: "Video", ofType: "mov")!
UISaveVideoAtPathToSavedPhotosAlbum(path, nil, nil, nil)
f3dm76
  • 317
  • 2
  • 13