本文介绍了媒体元素不会播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.
我正在尝试通过按按钮上的代码来创建媒体元素.
香港专业教育学院创建了一个很好的xaml媒体元素,但是当我尝试从c#代码创建一个媒体元素时,它将无法正常工作.

这是我的Xaml.

mediaelement name ="meXAML" loadingbehavior =手册"




还有背后的代码

Hi.
I''m trying to create a media element from code on a button press.
Ive created a xaml media element which works fine but when i try to create a media element from c# code it will not work.

Here is my Xaml.

mediaelement name="meXAML" loadedbehavior="Manual"




And the code behind

public partial class MainWindow : Window
    {
        MediaElement meC;
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnCode_Click(object sender, RoutedEventArgs e)
        {
            meC = new MediaElement();
            meC.LoadedBehavior = MediaState.Manual;
            meC.Source = new Uri("C:/Music/10cc/10cc - Rubber Bullets.mp3", UriKind.Relative);
            meC.Play();
        }
        private void btnXaml_Click(object sender, RoutedEventArgs e)
        {
            meXAML.Source = new Uri("C:/Music/10cc/10cc - Rubber Bullets.mp3", UriKind.Relative);
            meXAML.Play();
        }

    }



据我所知,两个媒体元素仅使用不同的方法设置为相同.

XAML媒体元素可以正常播放,但是生成的代码却不能.

我们将不胜感激.



As far as I can see both media elements are set the same only using different methods.

The XAML media element plays fine but the code generated one will not.

Any help will be greatly appreciated.

推荐答案


private void btnCode_Click(object sender, RoutedEventArgs e)
        {
            meC = new MediaElement();
            meC.LoadedBehavior = MediaState.Manual;
            mystackpanel.Children.Add(meC);
            meC.Source = new Uri("C:/Music/10cc/10cc - Rubber Bullets.mp3", UriKind.Absolute);
            meC.Play();
        }



我对WPF还是很陌生,我被卡在其中了一段时间.

再次感谢.



I''m still new to WPF and I was stuck on this one for a bit.

Thanks again.


这篇关于媒体元素不会播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-03 17:57