Stop playing sound called via SoundEffect.FromStream

前端 未结 1 1707
礼貌的吻别
礼貌的吻别 2021-01-06 07:58

I have some Windows Phone 7 code that starts playing a sound using SoundEffect.FromStream. I am using this instead of a normal media object as I need multiple audio clips to

相关标签:
1条回答
  • 2021-01-06 08:13

    You need to create a SoundEffectInstance which will store a reference to your SoundEffect. The SoundEffectInstance has a Stop method which can be called.

    SoundEffectInstance seiCircus;
    
    using (var stream = TitleContainer.OpenStream("circus.wav"))
    {
        var effect = SoundEffect.FromStream(stream);
        //create the instance
        seiCircus = effect.CreateInstance();
    
        FrameworkDispatcher.Update();
        //play sound via the instance
        seiCircus.Play();
    }
    
    //some event called to stop sound
    seiCircus.Stop();
    
    0 讨论(0)
提交回复
热议问题