使用 c# 设置 mediaElement 的来源 [英] Using c# to set the source of a mediaElement
本文介绍了使用 c# 设置 mediaElement 的来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 c# 编码设置媒体元素的来源(视频位于项目的资产文件夹中),我的编码如下:
I am trying to set the source of a media element using c# coding (the video is located in the project's assets folder), my coding is as follow:
//Defined as such in my XAML
mediaElement.Source = new Uri(@"Assets\HarlemCampus.wmv");
mediaElement.Play();
...但是当我单击按钮播放视频时收到以下错误:
...but I am receiving the following error when I click the button to play the video:
我不想在 XAML 中预设源,因为我想根据用户在运行时选择的单选按钮动态更改媒体元素的源,是否有办法做到这一点?
I don't want to preset the source in XAML because I want to dynamically change the media element's source, according to the radiobutton selected by the user at runtime, if there's a way to do this?
推荐答案
你必须使用资源文件 Uri:
You'll have to use a resource file Uri:
mediaElement.Source = new Uri("ms-appx:///Assets/HarlemCampus.wmv");
这篇关于使用 c# 设置 mediaElement 的来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文