Can't Play Sound on Xcode iphone simulator - iphone

I am trying to play a sound thats linked to a button, but I get the following error code. How can I fixed this problem?
2012-01-13 07:22:58.887 M3NYFAC3Z[5875:1e03] Error loading
/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:
dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn,
262): Symbol not found: _CFXMLNodeGetInfoPtr Referenced from:
/System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in:
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-01-13 07:22:58.892 M3NYFAC3Z[5875:1e03] Error loading
/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:
dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn,
262): Symbol not found: _CFXMLNodeGetInfoPtr Referenced from:
/System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in:
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-01-13 07:25:28.994 M3NYFAC3Z[5875:1e03] AQMEIO_Base::DoStartIO:
timeout 2012-01-13 07:25:29.271 M3NYFAC3Z[5875:1e03]
AQMEDevice(0x8831a00)::StartIO: error -66681 2012-01-13 07:25:29.272
M3NYFAC3Z[5875:1e03] CA_UISoundClientBase::StartPlaying:
AddRunningClient failed (status = -66681). [Switching to process 5875
thread 0x207] sharedlibrary apply-load-rules all
This is my code:
-(IBAction)playobey:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:#"renegadeyamaha" ofType:#"wav"];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer play];
}

You need to keep a reference to your AVAudioPlayer in an ivar/property somewhere. It's probably being created and then released immediately before it's had a chance to finish playing your sound.
I wrote a little AVAudioPlayer-based sound player class that might make your life easier:
https://github.com/nicklockwood/SoundManager

Related

Audio file doesn't play in iPhone 5

I use a code for playing a .caf audio file, the same code works good in an iPhone 4s and an iPad 2 but doesn't play at all in a iPhone 5...
this is the code:
-(IBAction)checkSound:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/Lunatic.caf", [[NSBundle mainBundle] resourcePath]]];
NSLog(#"%#",url);
NSError *error;
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
self.audioPlayer.numberOfLoops = 0;
self.audioPlayer.volume = 1;
NSLog(#"log audioplayer: %#",audioPlayer);
if (audioPlayer != nil)
{
[self.audioPlayer prepareToPlay];
[self.audioPlayer play];
}
if (audioPlayer.playing == NO)
{
NSLog(#"not playing, error: %#",error);
}
if([[NSFileManager defaultManager] fileExistsAtPath:#"file://localhost/var/mobile/Applications/0D3F5169-8DB1-4398-A09A-DB2FBADF57EF/myApp.app/Lunatic.caf"])
{
NSLog(#"file exist");
}
else
{
NSLog(#"file doesn't exist");
}
}
and this is the log output:
2013-08-07 20:05:52.694 myApp[7006:907] file://localhost/var/mobile/Applications/0D3F5169-8DB1-4398-A09A-DB2FBADF57EF/myApp.app/Lunatic.caf
2013-08-07 20:05:52.697 myApp[7006:907] log audioplayer: (null)
2013-08-07 20:05:52.701 myApp[7006:907] not playing, error: Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)"
2013-08-07 20:05:52.703 myApp[7006:907] file doesn't exist
As you can see the audioplayer log gives "null" and the error log says error -43....
but I repeat... with iphone 4s everything works good....
Any clue why is this happening? Did they change something with audio in iPhone 5? Could it be a setting in my iPhone 5 that's preventing the sound to play? Any help would be greatly appreciated
Have you called [audioPlayer prepareToPlay] prior to calling play? Also have you double checked the audioRoutes to ensure it is playing out of the proper channel?
Two good sanity checks are to:
1.) Call [audioPlayer isPlaying] and see if it returns yes or no after you call play.
2.) Set the AVAudioPlayerDelegate and wait for the callback on audioPlayerDidFinishPlaying: and see if it gets called after the length of your audio.
http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html
EDIT:
Since you're file actually isn't playing, that most likely means you have something wrong with the path you're calling.
Print out your path with an NSLog and also check to see if the file actually exists using:
if([[NSFileManager defaultManager] fileExistsAtPath:yourPath])
{
}

mpmovieviewcontroller not working in iPad application?

Below is my code for setting up mpmoviecontroller. Although I can hear the sound of the video, I cannot see the pictures of the video. I've searched through internet, but I could not find an error for my code. Could someone help me get out of this dilemma?
(Note that the path and url are correct~ :))
- (IBAction)playClicked:(id)sender {
NSString *path=[[NSBundle mainBundle] bundlePath];
path=[path stringByAppendingPathComponent:#"movies.bundle"];
path=[path stringByAppendingPathComponent:#"mean.mp4"];
NSURL *url=[NSURL fileURLWithPath:path];
NSFileManager *filemanager=[NSFileManager defaultManager];
if([filemanager fileExistsAtPath:path]){
NSLog(#"File exists at %#! You should be able to see the movie!:)",path);
MPMoviePlayerController *player=[[MPMoviePlayerController alloc] initWithContentURL:url];
if(player){
player.scalingMode = MPMovieScalingModeNone;
player.controlStyle=MPMovieControlStyleFullscreen;
player.movieSourceType=MPMovieSourceTypeFile;
[player.view setFrame:CGRectMake(0, navigationBar.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height-navigationBar.bounds.size.height)];
[self.view addSubview:player.view];
[player prepareToPlay];
NSLog(#"Ready to play for %#!",player.duration);
[player play];
NSLog(#"Played!");
}
}else{
NSLog(#"File does not exist!:(");
}
}
RUNTIME ERRORS:
2012-02-06 08:54:40.248 Board[1604:11f03] File exists at /Users/admin/Library/Application Support/iPhone Simulator/5.0/Applications/C468351E-3150-4397-B73A-8505D099B2C5/Board.app/movies.bundle/mean.mp4! You should be able to see the movie!:)
2012-02-06 08:54:40.276 Board[1604:11f03] Ready to play for (null)!
2012-02-06 08:54:40.277 Board[1604:11f03] Played!
[Switching to process 1604 thread 0x13e03]
[Switching to process 1604 thread 0x11f03]
2012-02-06 08:54:40.733 Board[1604:11f03] Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn: dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.740 Board[1604:11f03] Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn: dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.886 Board[1604:11f03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.894 Board[1604:11f03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.905 Board[1604:11f03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.928 Board[1604:11f03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.940 Board[1604:11f03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.947 Board[1604:11f03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
It seems that adding the code below will do the work.
player.movieSourceType=MPMovieSourceTypeFile;
[self.view addSubview:player.view];
[player setFullscreen:YES];

AVAudioPlayer getting error?

AVAudioPlayer getting error like this:
The operation couldn’t be completed. (OSStatus error 1954115647.)
I download audio mp3 file from some url using NSURLConnection and it is downloading 100% and save to DB as BLOB.
And then I am trying to play that file from AVAudioPlayer like this:
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithData:data error:&error];
if (player == nil)
{
NSLog(#"AudioPlayer did not load properly: %#", [error localizedDescription]);
}
else
{
[player play];
}
What I am doing wrong in this?
Did you try using initializing AVAudioPlay with URL and pointing the URL to the blob file ?
(id)initWithContentsOfURL:(NSURL *)url error:(NSError **)outError
It worked for me with the local URL setting.

Using exportAsynchronouslyWithCompletionHandler

I try to export an audio file from the iPod-Library. I want to create with this iPod-Library file an new file. In the AV Foundation Programming Guide in chapter Reading and Writing Assets there is a little example. However this code doesn't work for me. 4 errors happens
Export Status 4 Error Domain=AVFoundationErrorDomain
Code=-11800 "The operation could not be completed"
UserInfo=0x1edfa0 {NSLocalizedFailureReason=An unknown error occurred (-12124),
NSUnderlyingError=0x1ebdc0 "The operation couldn’t be completed. (OSStatus error -12124.)",
NSLocalizedDescription=The operation could not be completed}
My code
AVURLAsset *objAvUrlAsset = [[AVURLAsset alloc] initWithURL:[tempArray objectAtIndex:0] options:nil];
NSLog(#"%s objAvUrlAsset %#", __FUNCTION__, objAvUrlAsset);
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:objAvUrlAsset];
NSLog(#"%s compatiblePresets %#", __FUNCTION__, compatiblePresets);
if ([compatiblePresets containsObject:AVAssetExportPresetAppleM4A]) {
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
initWithAsset:objAvUrlAsset presetName:AVAssetExportPresetAppleM4A];
NSString * exportPath = [NSString stringWithFormat:#"testTrack1.M4A"];
NSURL *exportURL = [NSURL fileURLWithPath:exportPath];
exportSession.outputURL = exportURL;
exportSession.outputFileType = AVFileTypeAppleM4A;
exportSession.shouldOptimizeForNetworkUse = YES;
NSLog(#"%s export Session %#",__FUNCTION__, exportSession);
[exportSession exportAsynchronouslyWithCompletionHandler: ^(void) {
// export completed
NSLog(#"Export Status %d %#", exportSession.status, exportSession.error);
}];
[exportSession release];
}
the nslog message
-[MyLocalMusicLibrary getAllTracks] objAvUrlAsset AVURLAsset: 0x1dd5a0, URL = ipod-library://item/item.mp3?id=-212958261728896866
-[MyLocalMusicLibrary getAllTracks] compatiblePresets (
AVAssetExportPresetAppleM4A,
AVAssetExportPreset960x540,
AVAssetExportPresetLowQuality,
AVAssetExportPresetMediumQuality,
AVAssetExportPreset640x480,
AVAssetExportPresetHighestQuality,
AVAssetExportPreset1280x720
)
-[MyLocalMusicLibrary getAllTracks] export Session AVAssetExportSession: 0x1e85c0,
asset = AVURLAsset: 0x1dd5a0, URL = ipod-library://item/item.mp3?id=-212958261728896866,
presetName = AVAssetExportPresetAppleM4A, outputFileType = com.apple.m4a-audio
-[MyLocalMusicLibrary getAllTracks] Export Status 4 Error Domain=AVFoundationErrorDomain
Code=-11800 "The operation could not be completed"
UserInfo=0x1edfa0 {NSLocalizedFailureReason=An unknown error occurred (-12124),
NSUnderlyingError=0x1ebdc0 "The operation couldn’t be completed. (OSStatus error -12124.)",
NSLocalizedDescription=The operation could not be completed}
How can i fix this four errors. Do i need for this export the AVAssetReader and AVAssetWriter.
I got the same result from AVAssetExportSession, what the completely useless NSError is trying to tell you is that the path you're exporting to doesn't fully exist. You'll want to make sure that you create the path to the directory you're placing the file in using NSFileManager.
The problem for me was that I was trying to convert the file directly from the tmp directory after getting it from the UIImagePickerController
What I had to do was first save the file to the Library, then iterate over the ALAssetLibrary files to find the latest video saved. Then I converted that video to .mp4 and stored it int he application's local documents directory for use as I please.
Kind of ridiculous that this is necessary but it works.

AVAudioPlayer -> not working

Audio Player works fine if I initiate it for 20 to 30 times but after that it shows the following error
Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)"
The code currently I am using is as follows
- (void)playShortSound:(NSString *)fileName type:(NSString *)type
{
if (!isSound) {
return;
}
NSString *soundFilePath =[[NSBundle mainBundle] pathForResource: fileName ofType: type];
NSURL *fileURL = [[[NSURL alloc] initFileURLWithPath: soundFilePath] autorelease];
NSError *error;
AVAudioPlayer *newPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL: fileURL
error: &error];
//newPlayer.numberOfLoops = 0;
newPlayer.volume=1.0;
if (newPlayer == nil){
NSLog(#"%#",[error description]);
//[self playShortSound:fileName type:type];
//return;
}
else{
[newPlayer play];
newPlayer.delegate=self;
}
}
- (void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) player
successfully: (BOOL) completed {
if (completed == YES) {
NSLog(#"Sound Playing complete");
}else {
NSLog(#"error in completion of %#",player.url);
}
}
I was having the same problem and instead of init the player from url i did it from NSData.
NSString *soundFilePath =[[NSBundle mainBundle] pathForResource: fileName ofType: type];
NSData *soundData = [[NSData alloc] initWithContentsOfFile:soundFilePath];
NSError *error;
AVAudioPlayer *newPlayer =[[AVAudioPlayer alloc] initWithData: soundData
error: &error];
It seem to solved my problem hope it does yours.
By calling the method many times you are allocating the instance of AVAudioPlayer newPlayer many times. This will certainly cause you problems because of the memory allocated. Just make sure you release the objects that you own once you are done using them.
Did you set AudioSessionCategory?
{NSError *setCategoryError = nil;
BOOL success = [[AVAudioSession sharedInstance] setCategory: avaudiosessioncategoryplayandrecorderror: &setCategoryError];
}
I was trying to play files in my app by picking them from the iPod library when I got this error code. I found that in my iPod library on the device, I had a duplicate entry for the same song. Music player that comes with iOS was able to play one and not the other. That means one entry was not valid anyway. Probably removed from the device but iTunes/iOS did not do proper housekeeping.
It seems that the reference to the non-playable entry existed within the "Recently Added" playlist which is automatically created by the system. I had picked the same file from "Recently Added" playlist to play in the app.
Side Note: I had removed the file from the manually created playlist in which it existed (removed from the iOS device itself).
In short it seems that the file that I loaded into the AVAudioPlayer instance was not available on the device anymore or its referencing URL did not give back a proper file to play. So common reason for this error would be when the player does not get the file to load based on the URL given to it.