媒体元素不会播放

编程入门 行业动态 更新时间:2024-10-23 22:31:15
本文介绍了媒体元素不会播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨. 我正在尝试通过按按钮上的代码来创建媒体元素. 香港专业教育学院创建了一个很好的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.

推荐答案

您的手动媒体元素不属于您的页面.您是否正在寻找弹出式媒体元素?另外,您的Uri不是相对的,这是绝对的.相对表示您提供的路径没有绝对根,而是从应用程序所在的文件夹导航. Your manual media element is not part of your page. Are you looking for a popup media element ? Also, your Uri is not relative, it''s absolute. Relative would mean that the path you give does not have an absolute root, but navigates from the folder your app is in.

非常感谢. 我修改了代码以将中介元素添加到页面的堆栈面板中. Thank you very much. i modified the code to add the mediaelement to a stack panel in my page. 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.

更多推荐

媒体元素不会播放

本文发布于:2023-07-11 09:16:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1093551.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   媒体

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!