0

我有 2 个按钮,播放和暂停,当我点击暂停时,音乐停止,当我点击播放时,它从头开始播放音频。我想这样做,就像我按下 Play 时一样,它从我停止的地方恢复。

        private void PlayAudio()
    {


        McMediaElement.LoadedBehavior = MediaState.Manual;
        McMediaElement.Source = new Uri("../../SingAlong/Food Fit For A King/old king cole.mp3", UriKind.RelativeOrAbsolute);
        McMediaElement.Play();
    }

    private void button1_Click_1(object sender, RoutedEventArgs e)
    {
        PlayAudio();

    }

    private void button2_Click(object sender, RoutedEventArgs e)
    {
        McMediaElement.Pause();
    }
4

2 回答 2

2

当您设置属性时,您PlayAudio()的方法会重新加载媒体文件。Source这会导致您的对象在您调用时从头开始播放新加载的媒体Play()。而不是在事件处理程序中执行此操作button1_Click_1,您应该只调用该Play()方法:

private void button1_Click_1(object sender, RoutedEventArgs e)
{
    McMediaElement.Play();
}
于 2013-07-10T05:04:59.057 回答
0

这对我有用..

private void button1_Click_1(object sender, RoutedEventArgs e)
{
   McMediaElement.LoadedBehavior = MediaState.Pause;
}
private void button2_Click_1(object sender, RoutedEventArgs e)
{
   McMediaElement.LoadedBehavior = MediaState.Play;
}
于 2015-02-14T12:07:46.070 回答