I cannot seem to get this link:
https://api.soundcloud.com/tracks/54507667/stream
to work with the AVAudioPlayer. I have tested it in a Souncloud API started project and it seems to work just fine, however, when I try to implement it on my own it doesn't seem to work.
The error I get:
unrecognized selector sent to instance 0x9245d40
2013-01-04 17:56:04.699 CollectionViewTest[17023:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString absoluteURL]: unrecognized selector sent to instance 0x9245d40'
* First throw call stack:.....
The code:
NSURL *streamURL = [NSString stringWithFormat:#"%#",
allDataDictionarySound[#"stream_url"], nil];
NSLog(streamURL);
NSURLRequest *request = [NSURLRequest requestWithURL:streamURL];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
connectionPlay = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(#"test:");
NSError *playerError;
player = [[AVAudioPlayer alloc] initWithData:streamData error:&playerError];
NSLog(#"test:2");
The streamURL prints as expected, and then the program crashes.
the tests are not printed.
When everything else is commented out, and the NSURLRequest is left, it still crashes.
When I comment the whole block of code out, everything compiles and runs.
I now have attempted this:
NSData *_objectData = [NSData dataWithContentsOfURL:streamURL];
NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = 1.0f;
[audioPlayer prepareToPlay];
if (audioPlayer == nil)
NSLog(#"%#", [error description]);
else
[audioPlayer play];
This also returns the length error, I am at a loss on what could be causing this...
2013-01-05 13:46:16.536 CollectionViewTest[28224:c07] -[NSURL length]: unrecognized selector sent to instance 0x928a470
2013-01-05 13:46:16.546 CollectionViewTest[28224:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL length]: unrecognized selector sent to instance 0x928a470'
* First throw call stack:
streamURL is an NSString - not a NSURL
try:
NSURL *streamURL = [NSURL URLWithString: [NSString stringWithFormat:#"%#",
allDataDictionarySound[#"stream_url"], nil]];
I'm also not clear where the variable "streamData" is coming from (or what you expect to be in it).
The NSURLConnection is loading the data from the request asynchronously. It looks like you are assuming that the data is loaded synchronously and is available when you're initializing the "player" object. The data will (mostly likely) not be there when player is initialized.
Related
I don't know the reason but as soon as i get from a UITextField some data, like "Facebook", i call this code
- (IBAction)searchForAddress:(id)sender
{
[self loadRequestFromAddressField:_addressField];
}
- (void)loadRequestFromAddressField:(id)addressField
{
NSString *urlString = [addressField text];
[self loadRequestFromString:urlString];
}
- (void)loadRequestFromString:(NSString*)urlString
{
NSString *composedUrlString = [NSString stringWithFormat:#"http://www.google.com/search?q=%#",urlString];
NSURL *url = [NSURL URLWithString:composedUrlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:urlRequest];
}
Now the UIWebView loads correctly giving me the result of the google search, the problem is that when i try to enter some link it crashes giving me this error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WeBViewController searchURL:]: unrecognized selector sent to instance 0x8f38540'
What could be the problem??
Please check if your WeBViewController have methode name searchURL
it is very basic error.
It means you are calling method on instance of WeBViewController which is not implemented in it.
If you are still unable to fix this issue you can paste your code in question so we can take look at it.
I am trying to play audio and switch views with the same button..
- (IBAction)yourbuttonClicked:(UIButton *)sender
{
//start a background sound
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"tap2" ofType: #"caf"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath ];
myAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
myAudioPlayer.numberOfLoops = -1; //infinite loop
[myAudioPlayer play];
//for Switch view
ViewController *nextView = [[ViewController alloc] initWithNibName:#"ViewController2"
bundle: Nil];
[self.navigationController pushViewController:nextView animated:YES];
}
2014-03-02 19:07:46.817 Balloon Tap[847:70b] * Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '* -[NSURL initFileURLWithPath:]: nil string
parameter'
When I launch my simulator and click on the play button that performs the action it crashes and in my log it comes up with this error above..
How do I go about fixing this and editing my code?
It appears soundFilePath is Nil
Try this
NSURL *url = [NSURL fileURLWithPath:stringPath];
This removes the alloc, which may cause you some issues here. Also I'm sure you've checked, but is there an issue with the filename? Does it actually exist in your bundle? I.e is it being compiled with the rest of your code? Make sure that you add that file to your project, and it appears in a "Copy Bundle Resources" build phase in your executable's target in Xcode.
I am uploading video to Amazon S3 from iphone application. Earlier it was uploading fine but now all of a sudden it has stopped uploading the video and crashes the app. Below is the code for video upload
if(![ACCESS_KEY_ID isEqualToString:#"CHANGE ME"]
&& self.s3 == nil)
{
// Initial the S3 Client.
self.s3 = [[[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY] autorelease];
self.s3.endpoint = [AmazonEndpoints s3Endpoint:US_WEST_2];
}
NSString *videoName =[NSString stringWithFormat:#"%#",titleTextField.text];
NSString *trimmedString = [videoName stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSLog(#"name %#",trimmedString);
S3PutObjectRequest *por = [[[S3PutObjectRequest alloc] initWithKey:trimmedString
inBucket:[Constants pictureBucket]] autorelease];
por.contentType = #"movie/mp4";
por.data= videoData;
S3PutObjectResponse *putObjectResponse = [self.s3 putObject:por];
Here is the crash log
Terminating app due to uncaught exception 'AmazonServiceException', reason: '(null)' * First throw call stack: (0x2f370f53 0x399db6af 0xb6119 0xc39b3 0xc2f4d 0x533b9 0x5366f 0x2fd53e27 0x3a002c1d 0x3a002b8f 0x3a000c90) libc++abi.dylib: terminating with uncaught exception of type AmazonServiceException
Try setting the content length field and locally declaring the S3 client:
AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY]; //auto release deprecated, and not necessary with local declaration
s3.endpoint = [AmazonEndpoints s3Endpoint:US_WEST_2];
//post full video
por = [[S3PutObjectRequest alloc] initWithKey:generatedString inBucket:#"dormpicbucket"];
por.contentType = #"video/mp4";
por.data = capturedMovie;
por.delegate = self;
[por setDelegate:self];
por.contentLength = [capturedMovie length];
[s3 putObject:por];
Also make sure to debug this: [Constants pictureBucket] because it looks like youre using the sample/tutorial code from aws docs almost explicitly lol.
Hi, I'm new to the iOS app development I have created an app with two ViewController for the the second controller have created on class in called video controll view. Everything is fine but when I click the play I'm getting warning like this I don't what is this can anyone please help me on that I'm stuck here for long time.
2013-12-25 10:10:12.890 politicalapp[346:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
This is the code I have put for the video player:
- (IBAction)play:(UIButton *)sender {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"d" ofType:#"mp4"]];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL: url];
[self presentMoviePlayerViewControllerAnimated:player];
player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;[player.moviePlayer play];
player = Nil;
}
#end
Your problem is that pathForResource is returning nil. There can be a number of causes of this. Try changing it to:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"d.mp4" ofType:nil]];
If that doesn't solve it, just search the multiple of questions on stackoverflow named "Path for resource returns nil" and trouble shoot based on the various issues already discussed.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSURL *site_url = [NSURL URLWithString:[NSString stringWithFormat:#"%#/json/data/post?sid=%#", SECURE, PASSCODE]];
NSData *jsonData = [NSData dataWithContentsOfURL:site_url];
NSError *error = nil;
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
self.items = dataDictionary;
}
I am trying to parse json data. It works fine with data from the live server. However, when I change the link to http://localhost:8090. It stops working.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
I can access it from the data from the web browser. Does anyone know why is that?
Does it work on emulator and not on a real device?
You should never use localhost when developing apps, use the local IP for the server instead. Localhost is the machine who make the call to the server. When you try on the emulator and you have the server on the same machine it works because they are the same.
But when you try on a real device, localhost is the device, and the device doesn't have a server installed, so it will fail.
BTW, to test on a real device, it has to be connected to the same network.
What you need here is to implement the NSURLConnection and receive data from it
Check out this
NSURL *site_url = [NSURL URLWithString:[NSString stringWithFormat:#"%#/json/data/post?sid=%#", SECURE, PASSCODE]];
NSURLRequest *req = [NSURLRequest requestWithURL:site_url];
NSURLConnection *con = [[NSURLConnection alloc] initWithRequest:req delegate:self];
[con start];
and from the delegates get the response
this document can help you a lot in this