播放背景声音和声音的影响的Windows Phone 8 [英] Play Background Sound and Sound Effect in Windows Phone 8

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

问题描述

我已经研究了很多播放声音Windows Phone的8个设备,并找到多个解决方案,但他们不完全匹配我的情况。

我需要的:我在写一个使用文件作为背景声音的应用程序(C#+ XAML)(在浏览整个应用程序必须是活动的),并且还能够播放声音效果。

什么是问题:


  • 背景声音,我可以使用 BackgroundAudio 代理,而是因为我只希望在我的应用程序的后台播放的声音不符合我的要求,并停止,如果我的应用程序关闭或不活跃。

  • 对于声音效果 - 我试图的MediaElement 这是好的,但我不能设法让当我浏览整个应用程序它在某种程度上发挥。 Media关闭,如果我离开该网页 - 我想我可以利用这个对音效的把戏。此外,还有的 SoundEffect中这是不是一个相当不错的解决方案,因为它只能播放.wav文件...我可以使用它的声音效果只而不是背景音(大大小的文件)。

所以,我应如何进行播放背景声音(里面只有我的应用程序),如果我选择的MediaElement / SoundEffect中发挥应用程序的音效。我需要一个可以让我玩一次2的声音(背景和声音效果)的解决方案和背景音乐播放只有当应用程序运行(有效)...

到目前为止,我很困惑,只有设法解决音效问题。

任何建议都大大AP preciated。


解决方案

在与看到的问题你的的MediaElement 是您定义它是应用程序的一部分页面,并停止尽快消失了可视化树的播放(即后 OnNavigatedFrom )。

如果你定义了一个的MediaElement 是看得见作为应用程序框架的一部分,音频将继续播放,而你的应用程序被激活(您将需要处理停用事件,自然)。

如果你这样做的MediaElement 应该适用于你的背景音乐。

请注意你只能有一个单一的活跃的MediaElement 播放媒体在您的应用程序,但是你应该能够使用 SoundEffect中为您的音效。

更新:

要放你的的MediaElement 在一个框架,你需要创建一个自定义的 PhoneApplicationFrame 类/ XAML,加在的MediaElement 来的XAML,并参考App.xaml.cs您自定义的框架。

  //不添加任何额外的code此方法
私人无效InitializePhoneApplication()
{
    如果(phoneApplicationInitialized)
        返回;    //创建框架,但没有将其设置为RootVisu​​al之中;这允许溅
    //直到应用程序是准备呈现屏幕保持活跃。
    RootFrame =新MyCustomPhoneApplicationFrame();
    RootFrame.Navigated + = CompleteInitializePhoneApplication;

请参阅在Windows Phone的更多帧/页。

I have researched a lot on playing sounds for Windows Phone 8 devices and found multiple solutions but they don't quite match my case.

What I need : I'm writing an app (C#+XAML) that uses a file as background sound (must be active while navigating the whole app), and also to be able to play sound effects.

What are the issues :

  • For background sound I could use the BackgroundAudio Agent, but it doesn't meet my requirements because I want the sound to be played only in the background of my app, and to stop if my app closes or is not active.
  • For sound effects - I tried MediaElement which is okay, but I couldn't manage to make it somehow play while I am navigating the whole app. Media closes if I leave that page - I guess I could use this for the sound effects trick. Also, there's the SoundEffect which is not quite a good solution since it can play only .wav files... I could use it for sound effects only but not background sound (big sized files).

So, how should I proceed to play background sound (only inside my app) if I choose MediaElement/SoundEffect to play a sound effect in the app. I need a solution that would allow me to play 2 sounds at once (background and sound effect) and the background sound to be played only while the app runs (is active)...

So far I am confused and managed only to solve the sound effects issue.

Any suggestions are greatly appreciated.

解决方案

The issue you are seeing with your MediaElement is that you are defining it to be part of the application page and it stops playing as soon as it disappears off of the Visual Tree (i.e. after OnNavigatedFrom).

If you define a MediaElement to be "visible" as part of the application frame, audio will keep playing while your app is active (you will need to handle deactivation events, naturally).

If you do this MediaElement should work for your "background audio".

Be aware you can only have one single active MediaElement playing media in your app, however you should be able to use SoundEffect for your sound effects.

Update:

To put your MediaElement in a frame, you will need to create a custom PhoneApplicationFrame class/XAML, add the MediaElement to that XAML, and refer to your custom frame in App.xaml.cs.

// Do not add any additional code to this method
private void InitializePhoneApplication()
{
    if (phoneApplicationInitialized)
        return;

    // Create the frame but don't set it as RootVisual yet; this allows the splash
    // screen to remain active until the application is ready to render.
    RootFrame = new MyCustomPhoneApplicationFrame();
    RootFrame.Navigated += CompleteInitializePhoneApplication;

See this Dzone article for more about Frame/Page in Windows Phone.

这篇关于播放背景声音和声音的影响的Windows Phone 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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