I am getting the following error when returning from using the iPhoneUtils.PlayMovie() method. The background music that had been playing before beginning the movie does not resume.
Error Initializing AudioSession(errNO:1768843636)
I am getting the following error when returning from using the iPhoneUtils.PlayMovie() method. The background music that had been playing before beginning the movie does not resume.
Error Initializing AudioSession(errNO:1768843636)
I have noticed that it seems to be a much broader issue. I also get the same error when resuming on an iOS 4+ device, with the OpenFeint scripts when it attempts to resume the audio session, and pretty much any other situation where the audio session is paused.
Is this an issue with a change in implementation for music between older version of Unity iPhone and 3.0?
Unity 3.0 uses fmod, no longer openal, the audio session stuff works differently, non hw based compressed audio is supported, …
basically, the audiosession of unity must not be activated while something else tries to init / deinit its audio or it might missdetect the situation.
So what is the most agile way to handle background music and playing movies? Its easy enough for me to pause the music when the user clicks the play button, but as far as I know there are no events to catch when the movie returns to Unity. I could start a Coroutine when they click play that sleeps a few frames, and since Unity will be paused while it plays the movie it will not finish the Coroutine until it resumes, but this seems like a serious hack.
Could you please indicate the proper way to handle this situation?
EDIT:
A side note to this is why resuming on iOS4 would cause them same error. Yes it is going to resume the AudioSource which is playing the music when the task was paused but since there is still only a single AudioSource playing there should not be an issue with multiple objects accessing the uncompressed audio channel.
I would love some further clarification on this subject and some pointers on how to work around the current functionality.
The music file which is being played is fairly long so it is not really an option to use an un-compressed file for this.
I posted about this also and added a bug report (which has been closed with no comment ??!!)
Is it an error which means nothing?
Seems like the community is very quiet on this issue right now, I have posted a thread at UnityAnswers as well
http://answers.unity3d.com/questions/21868/error-initializing-audiosessionerrno1768843636
Feel free to post any other details you may have
Was your case number 378074? It’s unusual for a case to be closed without a report being sent to the originator. I’ll investigate what has happened but it is possible the bug has been fixed yet a report was not sent for some reason.
yes andeeee - (hopefully is fixed in next version - might be related to another issue…)
I have noticed another strange bug when playing non-compressed audio as well.
During normal game play there can be up to 4 non-compressed audio files playing plus 1 compressed background sound track which plays the duration of game play. I have noticed that on occasion Unity will skip playing one of the non-compressed sounds.
The non-compressed sounds are played using the PlayOneShot method on an AudioEmitter, and it is usually the same clip played multiple times for a gun shot. It seems that sometimes it will play 4-5 straight with no issue, other times it will skip playing one. I have been able to work around most of the other bugs with hacks but this is one that I really have no control over.
Also, note these sounds are not playing in very rapid of succession, usually they are spaced out by 1+ seconds.
Does anyone have information on why this would be happening?
I have the same error on iPhone 4 when I press on the home button. The music will not resume when resuming the application.
I made a workaround, I do not know if it can be of any help for you.
I add this component on my audio source and the music will restart. I call Play and Stop on this monobehavior instead of the AudioSource. When the application pauses it stores the information on the music.
You could do something similar at calling the OnApplicationPause manually when your video plays.
using UnityEngine;
using System.Collections;
[RequireComponent (typeof(AudioSource))]
public class Music : MonoBehaviour {
bool isPlaying = false;
float time = 0;
public void OnApplicationPause( bool pause )
{
if ( isPlaying )
{
if ( pause )
{
time = audio.time;
audio.Stop();
}
else
{
audio.time = time;
audio.Play();
}
}
}
public void Play()
{
isPlaying = true;
audio.Play();
}
public void Stop()
{
isPlaying = false;
audio.Stop();
}
}
Nice tip.
But I’m seeing more Audio errors I can’t figure out what is going on.
Using Unity 3.1 Basic versus iOS SDK 4.1 xcode 3.2.4
I reimported and changed all the music .mp3 to be not 3D sound, and adjusted the non-compressed to fit my need on the new editor.
But when I launch the OpenFeint (latest 2.7.5) dashboard from the menu, I got a crash which seems somehow related to Audio.
Here the console log:
Yes!
I solved the OF dashboard launch issue.
Apparently a check I performed on main menu audio channel was giving the issue!
Now I only have the no audio music coming back after dashboard closing issue left.
This is what the console puts out:
I’m running into a similar issue. In Scene A, I am playing an mandated intro m4v file (nothing else), then loading Scene B. I have several buttons in Scene B that each fire off audio. Any button with audio enabled pressed in Scene B crashes the application. If I disable the button press audio in Scene B, I am able to navigate about my menu and even load the game in Scene C without any trouble.
Here’s a snippet from my stack trace where the error occurs:
I hope we can get to the bottom of this. Perhaps is just a gross misunderstanding about how audio works in Unity 3.0?
So…I’ve found a (partial?) solution to my problem. I am building to iOS. My original audio clips were imported from mp3. Originally, I had 3D Sound, Decompress On Load, and Hardware Decoding toggle ON. When I went back to the audio clip for my button sound, turned Decompress On Load OFF, I still generate the AudioSession error code, but my application does not crash.
Worked for me for the time being; hope it works for you. Until then, I’ll chalk this up to ignorance of Unity’s audio handling.
Yes. This is right.
But even if is now not crashing, we are still experiencing the bug that will prevent Audio Channel of background music (mp3) not being restored when the App looses its focus. And not only with OpenFeint !
If the battery runs low and the “20% left” message comes up on iOS 4.x (not yet tested on 4.2) when I click “OK” the App looses the audio background !
This has something to do with a well-known FMOD bug and the fact that when a Unity App looses the focus, the Audio is being paused!
Hopefully will be fixed in the next releases. Meantime, I Keep on 1.7
Easy fix for running OpenFeint on Unity3.0 would be to open AppController+OpenFeint.mm (in your Assets/Editor/OpenFeint/Xcode/ directory), find all UnitySetAudioSessionActive function calls and just remove them all.
It looks like current AppController+OpenFeint.mm was written with Unity1.7 in mind, not Unity3.0.
Same problem with background music, when clicking on Home, the music won’t restart.
Strange if i put:
function OnApplicationPause()
{
music.audio.volume = 1;
music.audio.Play();
}
Then if i click on home button, then launch the app from multitask, the music plays. should not this happen in a something “OnApplicationPlay()” ?