Playing video on IOS - objective-c

I have downloaded the source files from
http://mobile.tutsplus.com/tutorials/iphone/mediaplayer-framework_mpmovieplayercontroller_ios4/
and the app works perfectly, but when I try to swap out my own video by changing the following code:
pathForResource:#"big-buck-bunny-clip" ofType:#"m4v"
to
pathForResource:#"example" ofType:#"mp4"
the app crashes when I try to play the video and I receive a message in the output saying:
"2012-09-13 20:32:59.106 BigBuckBunny[1081:11f03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[NSURL initFileURLWithPath:]: nil string parameter'
** First throw call stack:
(0x1722022 0x10f6cd6 0x16caa48 0x16ca9b9 0x4e53b 0x4e4c5 0x2da4 0x1723e99 0x36d14e 0x36d0e6 0x413ade 0x413fa7 0x413266 0x3923c0 0x3925e6 0x378dc4 0x36c634 0x1e1aef5 0x16f6195 0x165aff2 0x16598da 0x1658d84 0x1658c9b 0x1e197d8 0x1e1988a 0x36a626 0x297d 0x28f5)
terminate called throwing an exception(lldb) "
I have my new video file inside the folder with the original big-buck-bunny-clip.m4v file, and I put it in the project.
What am I doing wrong and how do I fix this?

I managed to play my own video by going to the file within Xcode and checking the box next to BigBuckBunny under Target Membership

Check file exits and filepath you r passing is nil:
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"example" ofType:#"mp4"];
if([[NSFileManager defaultManager] fileExitsAtPath:filepath])
{
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
else
{
NSLog(#"File not exists");
}

Related

Objective-c NSInvalidArgumentException Xcode7

Hey Guys I'm just gonna cut to the chase I was trying to play audio
- (IBAction)click1:(id)sender{
Drill.image = [UIImage imageNamed:#"Drillx2"];
AudioServicesPlaySystemSound(PlaySoundID);
}
- (IBAction)click2:(id)sender
{
Drill.image = [UIImage imageNamed:#"Drillx1"];
}
- (void)viewDidLoad {
NSURL *SoundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Drill" ofType:#"m4a"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)SoundURL, &PlaySoundID);
[super viewDidLoad];
}
And I get this error
'NSInvalidArgumentException', reason: '*** -[NSURL
initFileURLWithPath:]: nil string parameter'
Thanks,
Derek
Note : Yes the resource for the sound is named Drill.
In the code
NSURL *SoundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Drill" ofType:#"m4a"]];
It didn't find the given file in the bundle file path. make sure you have added file in the proper target and also build again after adding the resource to make sure it exist in the bundle
Reference : As written in the parameter Passing nil for this parameter produces an exception.

iOS Webview loadRequest from string returns nil on ipad and ipad retina

I've a menu on my app which loads local html file but it detects first if there is an updated file inside documents directory and if the file exists, the value of the html_path will load the updated file with its path on docs.dir of the app. This code works fine with iphone, and ipad retina 64 bit, but on ipad and ipad retina, the html_path variable returns nil.
NSString *html_path;
html_path = [[NSBundle mainBundle]
pathForResource:#"somehtml"
ofType:#"html" inDirectory:#"www"];
local_request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:html_path]];
[_webView loadRequest:local_request];
Below is the error that I got:
Terminating app due to uncaught exception `NSInvalidArgumentException`,
reason: `*** -[NSURL initFileURLWithPath:]: nil string parameter`
I wonder the cause of this error, please help as I'm stuck with this error.
I suspect this could be a problem with your resources not being included in the bundle for the application.
Select your target, go to "Build Phases" > "Copy Bundle Resources", press the "+" button and add your "somehtml.html" to the bundle.
I have solved the issue, it seems like
html_path = [[NSBundle mainBundle]
pathForResource:#"somehtml"
ofType:#"html" inDirectory:#"www"];
that code above does not return the correct path, or the correct string path to be recognized by the NSURL fileURLWithPath.
the solution that i came up with was, i separated the bundle path and put that on the string
NSString *bundle = [[NSBundle mainBundle] bundlePath];
then i use stringByAppendingPathComponent to concatenate the html file name
htmlFile = [bundle stringByAppendingPathComponent:#"www/somehtml.html"];

Error building from 5 to 6 IOS

I have IPad application for IOS 5.1, now i'm trying to build it for 6.0, and get an error:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
-[NSFileManager copyItemAtPath:toPath:error:]: source path is nil'
"
i found where is this problem, but i don't know how to correct it
in my AppDelegate
-(void)copyFileWithName:(NSString*)name Extension:(NSString*)extension ToDir:(NSString*)dirName withName:(NSString*)newName
{
NSString *folderPath = dirName;
NSString *filePathDocTxt = [folderPath stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.%#", newName, extension]];
NSString *filePathBundleTxt = [[NSBundle mainBundle] pathForResource:name ofType:extension];
//when i comment these two lines, my code compiles success, but i need these code
if(![[NSFileManager defaultManager] fileExistsAtPath:filePathDocTxt])
[[NSFileManager defaultManager] copyItemAtPath:filePathBundleTxt toPath:filePathDocTxt error:nil];
}
well the error is source path for the copyItemAtPath method is nil.
Since you copy from the bundle (your app) to another folder that implies that the file is not in the target.
make sure the file you attempt to copy is there and correctly added to the target (in Xcode)
to resolve the crash add an if to exclude copying if the item isn't there / assert it
NSString *filePathBundleTxt = [[NSBundle mainBundle] pathForResource:name ofType:extension];
assert(filePathBundleTxT);

iCloud file Upload error (NSFileWriteNoPermissionError = 513)

I'm trying to copy a file to iCloud using the follow code:
NSError *error;
//My Image Source file
NSURL *sourceURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"_219" ofType:#"jpg"]isDirectory:NO];
NSLog(#"source: %#", sourceURL);
NSFileManager *fileManager = [NSFileManager defaultManager];
//Discovering iCloud URL
NSURL *iCloudDocumentsURL = [[fileManager URLForUbiquityContainerIdentifier:nil] URLByAppendingPathComponent:#"Documents"];
NSLog(#"iCloudDocumentsURL: %#", iCloudDocumentsURL);
//Setting destination URL
NSURL *destinationURL = [iCloudDocumentsURL URLByAppendingPathComponent:#"image.jpg"];
NSLog(#"destination: %#", destinationURL);
//Copy file to iCloud
BOOL success = [fileManager setUbiquitous:YES itemAtURL:sourceURL destinationURL:destinationURL error:&error];
if (!success) {
#throw [NSException exceptionWithName:[error localizedDescription] reason:[error localizedFailureReason] userInfo:nil];
}
When I run this code I have the following result:
2012-12-31 15:15:30.888 iCloudTest[10614:907] source: file://localhost/var/mobile/Applications/B2202406-BEB8-41B6-A3C4-2327EFB85E54/iCloudTest.app/_219.jpg
2012-12-31 15:15:31.108 iCloudTest[10614:907] iCloudDocumentsURL: file://localhost/private/var/mobile/Library/Mobile%20Documents/xxxxxxxx~com~gazapps~iCloudTest/Documents/
2012-12-31 15:15:31.110 iCloudTest[10614:907] destination: file://localhost/private/var/mobile/Library/Mobile%20Documents/XXXXXXXX~com~gazapps~iCloudTest/Documents/image.jpg
2012-12-31 15:15:31.122 iCloudTest[10614:907] *** Terminating app due to uncaught exception 'The operation couldn’t be completed. (Cocoa error 513.)', reason: '(null)'
*** First throw call stack:
(0x38c312a3 0x32f1897f 0xbb617 0x3a31058d 0x3a350d71 0x3a34cae5 0x3a38e1c9 0xad241 0x3a351ad1 0x3a35165b 0x3a349843 0x3a2f1c39 0x3a2f16cd 0x3a2f111b 0x371295a3 0x371291d3 0x38c06173 0x38c06117 0x38c04f99 0x38b77ebd 0x38b77d49 0x3a34847d 0x3a3452f9 0xacff9 0x3627cb20)
libc++abi.dylib: terminate called throwing an exception
Looking at documentation, Cocoa error 513 means:
NSFileWriteNoPermissionError = 513,
So basically I'm without access to write stuff on iCloud... Looking at https://developer.icloud.com, everything seems to be ok (the documents folder is there).
What I'm doing wrong ?
iCloud has been working intermittently since December 30/31, even though everything may look good on developer.icloud.com. There's a discussion going on at the developer forums here:
https://devforums.apple.com/thread/176739?tstart=0
It's hard to diagnose iCloud issues at this point since it may just be problems on Apple's iCloud server. Some people have noted (on the discussion thread) that iCloud seems to be working better today than prior days so it may be worth testing your app again now.

xcode error: Parse Issue: Expected ';' after expression

I'm new to xcode and I'm trying to create a sound app. On line: theAudio.delegate = self; I'm receiving the error message:
error: Parse Issue: Expected ';' after expression
Below is a copy of the code.
- (IBAction)play:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:#"winning" ofType:#"mp3"];
if(theAudio)[theAudio release];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: path] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
Any help would be much appreciated.
I was getting a similar build errors in CoreFoundation.framework.
CFURL.h: Expected ';' after top level declarator
CFFileSecurity.h: Expected function body after function declarator
CoreFoundation.h: 'CoreFoundation/CFUserNotification.h' file not found
To fix them, I deleted my project's derived data. I did this in Xcode under the Projects Organizer, in the Organizer Window, Window > Organizer (Command-Shift-2).
Other Things I Tried First That Failed
Clean (Command-Shift-K).
git clean -dXf (doesn't delete derived data by default), which for me (since I ignore xcuserdata), removes:
MyApp.xcodeproj/project.xcworkspace/xcuserdata/
MyApp.xcodeproj/xcuserdata/
Restart Xcode.
Restart OS X.
Reinstall Xcode.
I was about to reformat my harddrive and reinstall OS X, which now I see would've worked too. I'm glad I figured out a much faster, more direct way to fix this issue.
Release the audio after play.
[theAudio play];
[theAudio release];
or try this one
-(void) myPlay: (NSString *) soundFile ofType:(NSString *) ext{
if (ext == nil) {
ext = #"caf";
}
//SystemSoundID soundID;
//create and assign soundID to a particular sound
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:soundFile ofType:ext]] , &soundID);
//AudioServicesPlayAlertSound(soundID);
//To play the sound
AudioServicesPlaySystemSound (soundID);
//Function to allocate a function to be called after the sound(with SoundID) ends(optional)
AudioServicesAddSystemSoundCompletion (soundID,NULL,NULL,soundCompleted,
(void*) self);
}