在背景中播放小音效 [英] Play small Sound Effect in background

查看:101
本文介绍了在背景中播放小音效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows Phone 8应用程序中。如何在背景中播放小音效。一次,在应用程序启动时。使用Splash Screen?

 Stream stream = TitleContainer.OpenStream(  sounds / SoundFile.wav ); 
SoundEffect effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();





我正在使用上面的代码,它正在播放声音文件。但我在主页构造函数中使用它。现在的问题是,每次我回到我的应用程序内的主页时都会播放声音。所以我不认为这是正确的方式,我只想玩一次。在应用程序启动时使用启动画面。

解决方案

您好,所有评论的人。主席先生,首先,所有我道歉,因为没有正确解释我的问题。实际上我是该网站的新用户。所以,我不知道如何正确发布问题。



现在,我自己解决了问题,我所做的就是,在App中放置相同的代码。 xaml.cs.在里面我把代码放在这个方法中



//启动应用程序时执行的代码(例如,从开始)

//重新激活应用程序时不会执行此代码


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);

}

In my windows phone 8 application. How Can I Play small Sound Effect in background. once, on application start up. With Splash Screen?

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.

解决方案

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);
}


这篇关于在背景中播放小音效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆