Audiostreamer on iOS - Using with ARC - iphone

I'm using matt gallagaher's AudioStreamer class. I've used it before in a project before ARC came along and it worked fine. When I added the class to a project which uses ARC, I came across lots of errors which I could fix by adding __bridge references etc...
So the app now runs, but when I start the streamer with [streamer start] I keep coming across this error which I don't know how to fix. The compiler stops at the function below in Audiostreamer.m with the error Thread 8: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0) - I don't know what to do from here...please help.
if (CFReadStreamSetProperty(stream, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue) == false)
{
[self presentAlertWithTitle:NSLocalizedStringFromTable(#"File Error", #"Errors", nil)
message:NSLocalizedStringFromTable(#"Unable to configure network read stream.", #"Errors", nil)];
return NO;
}

I have exactly error with using FreeStreamer by muhku (good library, recommended).
Check that you give correct/not nulled url to AudioStreamer.

Give my StreamingKit library a go. It has the same functionality as AudioStreamer but is built with ARC and has quite a few additionally pieces of functionality.
https://github.com/tumtumtum/StreamingKit

I was getting the same problem, but I disable arc and now is working fine, the only problem that I got is that when I slide my slider I get a new value to seekToTime: , but is not playing starting from the new value. Any idea what that is ?

CoreAudio seems to work internally using exceptions, so if you have an exception breakpoint installed, this is what you will see. Just disable the breakpoints and it'll work.

Related

audioPlayerEndInterruption does not work if CALLER cancels

I am using audioPlayerEndInterruption to bring back game music after an 'interruption'.
It seems to work perfectly for all scenarios tested, except:
if a call is received but the caller hangs up (before being answered), the game comes back, but the audio track does not.
As I say, all other call interruption scenarios work, the track does come back. I wonder if this is some kind of iOS bug? Has anyone heard of this problem? Seems strange.
I'm inclined to forget it for the time being, but it is annoying!
My code is like this:
-(void)audioPlayerEndInterruption:(AVAudioPlayer *)player withFlags:(NSUInteger)flags{
if(flags == AVAudioSessionInterruptionFlags_ShouldResume && player != nil){
[player play];
}
}
Would appreciate any advice. Thanks.
Better late than never.
I'm also experiencing this issue. It looks like a bug (at least in ios 5.1) because if all AVAudioPlayers are stopped, and openAL sounds are playing only, AVAudioSession delegate methods are called as expected (yet AVAudioPlayer's do not).
So if AVAudioPlayer is running I use a workaround:
just add to AppDelegate::applicationDidBecomeActive call to your audioPlayerEndInterruption handler with some checks if appropriate (if sound manager exist and so on). This works for me.

Xcode deosn't detect a framework

I have added ALAssetsLibrary framework to my project and for some reason XCode doesnt detect it.
I have no code completion, and XCode gives a warning and then crashes when I use the following code
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupWithTypes:ALAssetsGroupAlbum
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error){
NSLog(#"A problem occured");
}];
It doesnt detect what ALAssetsLibrary is and the warning which leads to a crash is
warning: 'ALAssetsLibrary' may not respond to '-enumerateGroupWithTypes:usingBlock:failureBlock:'
Why isnt XCode detecting the framework?
I have added it to my project as well as imported it.
I would really appreciate the help with this, I dont understand what I did wrong. Thanks
Choose "Device", not "Simulator".
First, you're importing AssetsLibrary.h, are you sure this refers to the class ALAssetsLibrary and ALAssetsGroupAlbum?
Second, I'm not sure it failing to find it is the problem, I imagine there would be a different error in that case, such as, this class is not defined, first use in function.
It's saying unrecognized selector, which means there might be a problem with your pointers.
Have you got your SDK set to 3.x? Blocks were only introduced in iOS 4.0, along with all the methods relating to them.

AudioStreamer stops when switching between cellular and wifi

I'm using AudioStreamer and everything works fine, except when I switch between cellular and wifi network. It imediately stopps.
I tested it without leaving the app by switching off the wifi network, so i can proof the problem is not caused when the app is in the background.
So, did anyone have problems with AudioStreamer when switching between networks ?
cheers Simon
It makes sense as the network change is an interruption in data flow… Put a breakpoint in the stop and pause methods to see what is calling it. My suspicion is that it is being called in the handleInterruptionChangeToState method (line 1924)
Some time back i also had the problem with the AudioStreamer when the 4.0 background feature was added it stops buffering as soon as the app goes in the background. It was solved because i missed the key in the info.plist :) . But it was giving me problems after that also crashes and sometimes it use to stop.
So i just used NSURLConnection to download the data and provide it to the player. It worked g8. And if it had some kind error it worked well with the below method
(void)applicationWillEnterForeground:(UIApplication *)application
But i think changing the network can cause problem but you can try with a sample app with NSURLConnection.

how to know that MPMoviePlayerController is playing in Iphone OS 3.0

I need to know if at an specific moment the MPMoviePlayerController is playing.
In iphone 3.0 it is not firing the MPMoviePlayerContentPreloadDidFinishNotification.
Does anyone knows any solution?
Thanks in advance!
So thanks for the answer.
I fix this so I will post the answer.
The answer is that MPMoviePlayerContentPreloadDidFinishNotification is NOT FIRED if you invoke play() right after the initialization.
To have MPMoviePlayerContentPreloadDidFinishNotification which works ok you have to invoke the "play()" method of the MPMoviePlayerController when the MPMoviePlayerContentPreloadDidFinishNotification is fired ( I mean in the MPMoviePlayerContentPreloadDidFinishNotification method ). In this case it always works.
Tested on 3.0, 3.1 and 3.1.2
Same question (but no answer) here and several other reports can be found on other sites (e.g. here)
Not ideal, but it seems targeting 3.1 solves the problem.
A workaround maybe to set the MPMoviePlayerController property scalingMode to something other than the default MPMovieScalingModeAspectFit ( e.g. MPMovieScalingModeNone and make sure your video is correct size) before calling play and then hook the MPMoviePlayerScalingModeDidChangeNotification event instead. it seems to get called (more than once!) as soon as the movie starts playing. Of course it will also be called if the user changes the scaling mode manually, so code for this. It's dirty but may help you?

NSSound undeclared on iPhone?

sound = [[NSSound alloc] initWithContentsOfFile:#"staticbeam09.wav" byReference:YES];
Code referenced from Apple docs. Getting an error when I put this in viewDidLoad. If I put
NSSound *sound;
in the header file, I get the specifier-qualifier error at the top of my implementation file. What do I have to do to make this work? I was just pasting the code from Apple's documentation - has this been deprecated? Thanks for your help!
There is no NSSound class in iPhone SDK
It's only for MacOS
Oxigen’s right. If you want to play sounds on iPhone, there are several options. Probably the easiest one is using Audio Services (example wrapper), then there is AVAudioPlayer and then you can also use OpenAL (I’ve written a very basic OpenAL sound effect engine called Finch). Depends on what you need to do.
http://icodeblog.com/2009/05/04/iphone-game-programming-tutorial-part-4-basic-game-audio/
that is how i did the audio bg music and sound effects at the end for iconquer