简体   繁体   English

在WP7应用中添加两个音乐源

[英]Adding two music sources in WP7 app

In my WP7 gaming app , I want two music files to run. 在我的WP7游戏应用程序中,我希望运行两个音乐文件。 One is the background music and another follows the user action , say, user kills the enemy. 一种是背景音乐,另一种是跟随用户的行为,例如,用户杀死了敌人。 I am using MediaElement to do this. 我正在使用MediaElement来做到这一点。 I am facing two issues. 我面临两个问题。

1) How to loop background music ? 1)如何循环播放背景音乐?

2) As soon as second music starts, the first music stops and does not start back when the second music stops. 2)第二音乐开始时,第一音乐停止,第二音乐停止时不开始播放。 I do not want background music to stop, they should overlap. 我不想停止背景音乐,它们应该重叠。 How to do this ? 这个怎么做 ?

I am using silverlight. 我正在使用Silverlight。

XAML XAML

<MediaElement x:Name="stroke"   AutoPlay="False" />
<MediaElement x:Name="bmusic"   AutoPlay="True" />

C# C#

 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);

        var settings = IsolatedStorageSettings.ApplicationSettings;
        if (settings.Contains("bm"))
        {
            string hy=(string)settings["bm"];
            //check if user has disabled music play
            if (hy == "1")
            {
                bmplay = 1;
                // play background music
                bmusic.Source = new Uri("bmusic.mp3", UriKind.Relative);

                bmusic.Play();

            }
            else
            {
                bmplay = 0;
            }
        }
        else
        {
            bmplay = 1;
            // play b music
            bmusic.Source = new Uri("bmusic.mp3", UriKind.Relative);

            bmusic.Play();
        }



        if (NavigationContext.QueryString.TryGetValue("msg", out msg))
        {
           //  textBox1.Text +=" "+ msg;
             find_move();
        }


    }

For repeating music you can use this: 要重复播放音乐,您可以使用以下方法:

Song s = Song.FromUri("song", new Uri(path));
FrameworkDispatcher.Update();
MediaPlayer.IsRepeating = repeat;
MediaPlayer.Play(s);

And try to use SoundEffect for sounds, they can be played simultaneously with background music. 并尝试将SoundEffect用于声音,它们可以与背景音乐同时播放。
Sound effect in windows phone 7 Windows Phone 7中的音效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM