ios - music player stops as soon as I enter my app - ios

I am tasked to finding why this app stops the Music Player on my ipod. Currently, in XCode, i have set breakpoints in the very first line of main(), and still, when i reach that line, the Music Player has already stopped.
I can imagine that any static constructor would have already run, but I've searched for the obvious culprits (any mention of AVAudioSession), and found nothing that had run before main().
Since the codebase is just huge, it would be a pain to blindly search for every constructor in every file, without knowing what I'm looking for.
Can you tell me if there is any kind of XCode project property that stops external audio from playing, or anything that I could look for?
Thanks
EDIT: I've narrowed it down a lot.
First, for some reason, XCode seems to ignore most of my breakpoints which mislead me completely.
It was indeed a static initialization of an object, which eventually leads to this call:
newDevice = alcOpenDevice(NULL);
For some reason, I can actually get a breakpoint here. Go figure...
So, I have the music playing on this line, but not after I run it. It seems openal's initialization of the device shuts off all external music, for some reason... Trying to understand why, and how can i circumvent it...

Check the documentation for AVAudioSession's Categories, it sounds like your app has a nonmixable AVAudioSessionCategory, can you reproduce if you change it to AVAudioSessionCategoryAmbient?

Have you tried setting the music to play on load through the AppDelegate ?
Try having it so if the user loads back into the app it continues playing music.

Ok, I found out the problem. For some reason, XCode wasn't helping out. So I had set lots of breakpoints everywhere to see what would run before getting to main. This is where XCode failed me, because I knew the code was running, but for some reason, the breakpoints weren't being triggered. Also, for some reason, others did, so I still have that particular mistery to solve.
Apart from that, the problem was initializing OpenAL just before AVAudioSession got configured with AVAudioSessionCategoryAmbient. After switching those two around, everything worked just fine.
Thank you all for your help!

Related

Why is SKAction.playSoundFileNamed crashing?

NOTE:
It has been a few days and I still am having this problem. One thing that would be helpful, is to know some troubleshooting ideas to try, so I can track down what is causing the crash. Any help that would lead me in the correct direction would be greatly appreciated.
I'm running in Xcode 8.2.1 on the simulator, as well as on several different iOS devices. I get the same problem wherever I go.
I have imported a small mp3 file into my spritekit project, called "cat_meow_1.mp3"
when I select the file, in Xcode, and hit the play button, it plays normally. Incidentally I have tried with various different files in various formats, with the same results.
in my code, which complies okay, when I get to the line:
run(SKAction.playSoundFileNamed("cat_meow_1.mp3", waitForCompletion: true))
I get a crash with the error message,
error: use of undeclared identifier '$r0'
Any suggestions how to debug this problem, or to figure out what I did wrong?
I also tried to preload the sound and make a class property, but got the same error. Here's what it looks like:
UPDATE:
After reinstalling Xcode, I still have the same problem. With certain files, I get white noise, while with other ones I get the error here. What else could be wrong with my system to cause this problem?
UPDATE 2:
tried my experiment on a separate mac, and basically it worked just fine. I reinstalled my OS, and got the same problem, with a little more of an error message this time, which reads:
2017-01-18 18:10:09.397565 sound attempt 2[533:124220] [DYMTLInitPlatform] platform initialization successful
2017-01-18 18:10:11.058506 sound attempt 2[533:124042] Metal GPU Frame Capture Enabled
2017-01-18 18:10:11.059146 sound attempt 2[533:124042] Metal API Validation Enabled
error: use of undeclared identifier '$r0'
warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.
After a couple days, I finally gave in and used Clean My Mac 3 to completely remove Xcode, as well as any and all related files... I must not have caught everything when previously I uninstalled/reinstalled it, because this time, there were none of my custom settings at all when I ran the reinstalled app.
It works now, thankfully, and I can get back to work.

What's wrong with this aupreset for AUSampler?

I created this aupreset to be loaded into an AUSampler in iOS. I followed the process outlined here and used the EPSSampler class for the same post. So, if I run my app in the iOS simulator, on iOS 9, the aupreset loads and I get to play notes. If I run the same app on a device running iOS 6, the preset loads but I get no sound. I have used the same process on simulator and device in the past, but always by filtering the built-in sine wave generator, never with audio samples. Can someone spot what I'm doing wrong?
EDIT I have no way of testing the app on any device running iOS above 6, at least for now.
EDIT 2 To clarify further, this is how my project looks in Xcode, so you know that my files are going to the right places – i.e. the audio files are going to the Sounds folder within the app bundle (I double checked, just to be sure).
EDIT 3 So, I took the Trombone.aupreset from LoadPresetDemo and manually plugged my audio files into it. Magically, it worked. So I figured I'd load it into the AUSampler's GUI through AU Lab, and make whatever changes I needed to make it sound right – i.e., increasing the release time. It stopped working. So, i manually tweaked the working copy to roughly match what I needed (the docs on aupresets plists are surprisingly unhelpful) and I'm rolling with it. It would seem that AUSampler is messing up the preset, at least for iOS 6 on device, which, currently, is the only device I have to test on. Insights?
I didn't really look that deeply, but the file://localhost//Library/Audio/Sounds/C.caf in your file references looks a little fishy. Mine looks like this /Users/dave/Library/Audio/Sounds/C6.wav. Maybe the file:// part is throwing it off.
Create a directory in your iOS project named Sounds (just like your image shows) and put your caf files in there. The URLs will be groked by iOS.
Here is a post that goes into detail.

App crashes on startup, only on my computer

I have Xcode 6.1.1, and my app crashes on start up. It never reaches the start view (not even its awakeFromNib), but crashes on UIApplication on main. When it breaks there, I get NOTHING in the debug. Literally nothing. If I continue the program anyways it will work, flawlessly. But it ALWAYS breaks at UIApplication at startup. So I press "continue" and the app works as intended. I've tried the project on another computer, works fine there. I've tried reclone my project, doesn't work on my computer/xcode, but on another computer. It's just as if I have a breakpoint on UIApplication main...
If I reverse to previous commits, like 18 commits back, it works fine. If I then remerge with latest commit, it crashes on UIApplication again.
Starting to get upset here, anyone who has the faintest idea of what could be wrong here?
Try this:
remove all breakpoints.
make sure you are not sharing breakpoints
in repository ;), check your git ignore file if needed, check data in
git.
add exception break point to all Objective-C Exceptions
run the project
Found it. The problem was that there was a breakpoint set on "All exceptions" in the breakpoint data. It felt so weird that I could force to continue and it would work flawlessly, so it was indeed a breakpoint sneaking about.
Thanks for the help, I would not have found this without your help.

What is the simplest way to play a MIDI note for an indefinite duration in iOS?

I want to play instrument 49 in iOS for varying pitches [B2-E5] for varying durations.
I have been using the Load Preset Demo as reference. The vibraphone.aupreset does not reference any files. So, I had presumed that:
I would be able to find and change the instrument in the aupreset file (unsuccessful so far)
there is some way to tell the MIDI interface to turn notes on and off without generating *.mid files.
Here's what I did:
Duplicated the audio related code from the proj
removed the trombone related files and code (called loadPresetTwo: in place of loadPresetOne: in init (as opposed to viewDidLoad)),
added a note sequence, and timer to turn off the previous note, and turn on the next note.
Build. Run. I hear sound on the simulator.
There is NO sound coming from my iPhone.
I have triple checked the code that I copied as well as where the calls are taking place. It's all there. The difference is the trombone related files and code are absent. Perhaps there is some dependency that I'm not aware of. Perhaps this is problem rooted in architectural differences between the simulator running on remote Mac VM and the iPhone. Perhaps I can only speculate because I don't know enough about the problem to understand what questions to ask.
Any thoughts or suggested tests would be great!
Thanks.
MusicPlayer + MusicSequence + MusicTrack works. It was much easier than trying to guess what code in the demo was doing.

iOS crash only when NOT running via XCode. Concidence?

My app was crashing only when not running using XCode debugger. It was hard to track because I can't debug but I finally figured it out. It was because of calling release on some object not owned by me. Before I corrected it I searched and found 2 related questions here (links below)
iOS App Crashes when running by itself on device, does not crash when running through Xcode using debugger, or in simulator
iPhone crash only when device not connected to xcode, how to understand the crash log?
None of the above question has answered why no crash when running via debugger.So my question is why it happens ? I know reasons for debug/release specific crashes but this is crazy. Is it just by chance although it happened more than 10 times.
What you describe is not atypical of obscure memory-related bugs. You might also want to use debug-malloc at such times. Although that is not guaranteed to find everything. The reason (and it's been happening probably as long as there've been source-level debuggers) is that memory is laid out at least somewhat differently in debuggable code, and when running under the debugger. So the error results in a different piece of memory being (harmlessly) corrupted when under the debugger. When not under the debugger the location corrupted is actually something that your code cares about, and it crashes.
The same could happen in reverse, but you'd never know - if it crashes when run debuggable, you'd find it before switching to running outside the debugging environment.
Reiterating #jyoung's answer since I didn't see it the first time I glanced through:
Try running with Zombie Objects turned off.
In debug mode if you have it turned on it is handling memory allocation differently. Try running it without.
Go to Edit Scheme... > Run > Diagnostics. Then make sure zombie objects is turned off:
Then run through your code path again.
I had this same issue while working on a project modularised with Xcode Frameworks. Even after removing all the logic in AppDelegate and only returning true inside application:didFinishLaunchingWithOptions, I was still getting the crash. Then I switched to my project settings, in the Frameworks, Libraries, and Embedded Content section and changed the embed option for the frameworks I added to Embed & Sign. This was what fixed the issue for me. I hope someone finds this helpful.
I was having this problem as well and was fortunate to figure out the cause quickly, hopefully by posting here I can save someone else some wasted time. To clarify, my app would run with no issues when launched directly from XCode, but would crash immediately when launched manually on the iPad.
The app in question is written in Obj-C but relies on some 3rd party code written in Swift. The Swift code is included in the app as an embedded framework. I had to set "Embedded Content Contains Swift Code" to Yes in the Build Settings for the app (under Build Options), then the problem went away.
I experienced this symptom when I made a NSString, sent a UTF8String from it to another object, and assigned it to a char pointer. Well, it turns out that I forgot to retain the original NSString, which wouldn't have mattered anyway, since I also failed to realize that the UTF8String method (which is presumably an object that gives access to the pointer itself) operates in the autorelease pool. That is, retaining the NSString itself did not fix the problem.
I suppose this appeared to work just fine when attached under the debugger only because I had zombies enabled, so the pointer I had was still valid. I should see if this is the reason it worked; if so, this is a good reason to test with and without NSZombie enabled.
At any rate, this was probably poor design to begin with, and a pretty obvious newbie memory management mistake once I found it. Luckily the console in the Organizer window gave me some hints on where to start looking, and debugging ultimately showed me where my pointer's value was changing. Hope this helps anyone who finds the way here.
I had this issue when accessing SQLite databases from outside the [[NSBundle mainBundle] resourcePath] directory, which caused iCloud errors.
I discovered the error only by installing a Console app onto my iPhone which logged the errors.
Once I accessed the databases from the correct directory, the errors disappeared and the application booted correctly.

Resources