[英]Windows IoT Raspberry Pi 3 c# MediaPlayer.mediaEnded
I am new to this. 我是新来的。 I am trying to do a Audio Message Player on Rasp Pi 3 with Win IoT core. 我正在尝试使用Win IoT核心在Rasp Pi 3上执行音频消息播放器。 I manage to play audio file from my USB thumbdrive but I need to know when the audio file has completed playing. 我设法从USB拇指驱动器播放音频文件,但是我需要知道音频文件何时完成播放。
mediaPlayer = new MediaPlayer();
mediaPlayer.MediaEnded += MediaPlayer_MediaEnded;
private void MediaPlayer_MediaEnded(MediaPlayer sender, object args)
{
GeneralMessage.Text = "Message Complete!";
}
i get an error message with the above code. 我收到上述代码的错误消息。
System.Exception occurred
HResult=0x8001010E
Message=The application called an interface that was marshalled for a
different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
Please help. 请帮忙。
The reason of your problem is that, UI changes must be made on the UI thread but MediaEnded event is raised on a different thread. 问题的原因在于,必须在UI线程上进行UI更改,但是在另一个线程上引发MediaEnded事件。
In windows IoT Core, when you update the element in UI from another thread, please use the Dispatcher.RunAsync method. 在Windows IoT核心版中,当您从另一个线程更新UI中的元素时,请使用Dispatcher.RunAsync方法。
Task.Run(async () =>
{
//this part is run on a background thread...
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
()=>
{
//this part is being executed back on the UI thread...
GeneralMessage.Text = "Message Complete!";
});
});
Please reference here Media items, playlists, and tracks .This article showed how to use MediaSource , and included the operations performed within a CoreDispatcher.RunAsync call. 请在这里参考媒体项目,播放列表和曲目 。本文介绍了如何使用MediaSource,并包括了在CoreDispatcher.RunAsync调用中执行的操作。
i manage to solve the invoke thingy.. code as follow 我设法解决调用thing ..代码如下
private async void MediaPlayer_MediaEnded(MediaPlayer sender, object args)
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
GeneralMessage.Text = "Done playing.";
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.