Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
In my windows phone 8 application. How Can I Play small Sound Effect in background. once, on application start up. With Splash Screen?
C#
Stream stream = TitleContainer.OpenStream("sounds/SoundFile.wav");
SoundEffect effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();


I am using above code, and it is playing sound file. but i am using it in mainpage constructor. Now problem is, It is playing sound every time i am coming back to mainpage within my application. So i don't think it is the right way, I want to play it only once. On application start up with splash screen.
Posted
Updated 7-May-14 3:20am
v5
Comments
Thanks7872 7-May-14 8:45am    
Title is not meant to explain everything about your question. Its just an overview. This question is not at all clear. There are very less chance you will get resolution.
Member 10801309 7-May-14 9:07am    
Sir, i updated my question, and tried as much as possible to explain. I just want to play a small .wav file once on application start up, when splash screen in application comes up. Thank you.
[no name] 7-May-14 9:09am    
Just dumping 4 lines of unformatted code here is not an "explanation". You need to tell us what the problem is with your code.
Member 10801309 7-May-14 9:11am    
Sir, i am using that code to play audio file. But i am able to use it in mainpage constructor, now problem is every time i am coming back to mainpage it is playing that sound. But i want to play it only once with splash screen that's it. sir, I hope you are getting what i am trying to explain.
Member 10801309 8-May-14 0:25am    
Hello Sir, Any help would be really appreciated. Actually i am not getting a single example, how to do it. I am not even sure if it is possible to do so in WP8 or not, The same application is developed by our android and ios team, and they did it very easily, They are able to play that sound file once on application start up with splash screen.

1 solution

Hello, To All who commented. Sir, first off all i apologies, for not explaining my question properly. Actually i am a new user to the website. So, i did'nt know how to post question properly.

Now, I solved the problem myself, all i did is, placed the same above code in App.xaml.cs. Inside it i placed the code in this method

// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated

private void Application_Launching(object sender, LaunchingEventArgs e)
{
Stream stream = TitleContainer.OpenStream("sounds/SoundFile.wav");
SoundEffect effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
System.Threading.Thread.Sleep(DateTime.Now.TimeOfDay.Seconds + 2000);
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900