C# UWP MediaPlayerElement播放音频两次

C# UWP MediaPlayerElement播放音频两次,c#,audio,uwp,windows-media-player,C#,Audio,Uwp,Windows Media Player,我正在用UWP C#制作一个应用程序,我的问题是MediaPlayerElement同时播放音频两次。第二个音频稍有延迟。如果我关闭或暂停视频,其中一个音频停止,另一个继续播放 player.AutoPlay = false; player.Source = MediaSource.CreateFromUri(new Uri(link)); player.MediaPlayer.Play(); 停止: player.MediaPlayer.Dispose(); xaml: 我正在使用这个X

我正在用UWP C#制作一个应用程序,我的问题是MediaPlayerElement同时播放音频两次。第二个音频稍有延迟。如果我关闭或暂停视频,其中一个音频停止,另一个继续播放

player.AutoPlay = false;
player.Source = MediaSource.CreateFromUri(new Uri(link));
player.MediaPlayer.Play();
停止:

player.MediaPlayer.Dispose();
xaml:


我正在使用这个Xaml:

<UserControl
x:Class="BurningSeries.ui.VideoPlayer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Margin="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
d:DesignHeight="300"
d:DesignWidth="400">

<Grid Background="Black">
    <MediaPlayerElement x:Name="player" AreTransportControlsEnabled="True"></MediaPlayerElement>
</Grid>

我尝试了您的上述代码,但无法重现该问题。你能提供一份详细的报告吗?
<UserControl
x:Class="BurningSeries.ui.VideoPlayer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Margin="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
d:DesignHeight="300"
d:DesignWidth="400">

<Grid Background="Black">
    <MediaPlayerElement x:Name="player" AreTransportControlsEnabled="True"></MediaPlayerElement>
</Grid>
public sealed partial class VideoPlayer : UserControl
{
    public VideoPlayer()
    {
        this.InitializeComponent();
    }

    public void setSourc(string link)
    {
        player.AutoPlay = false;
        player.Source = MediaSource.CreateFromUri(new Uri(link));
        player.MediaPlayer.Play();
    }

    public async void pause()
    {
        await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            player.MediaPlayer.Dispose();
        });
    }

    public double Duration()
    {
        double result = 0;
        try
        {
            result = player.MediaPlayer.NaturalDuration.TotalSeconds;
        }
        catch { }
        return result;
    }

    public int Time()
    {
        int result = 0;
        try
        {
            result = player.MediaPlayer.Position.Seconds;
        }
        catch { }
        return result;
    }
}