MediaElement.MediaEnded 事件未触发 [英] MediaElement.MediaEnded event not firing

查看:28
本文介绍了MediaElement.MediaEnded 事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从 Windows Phone 移植的应用程序 -> Windows 8 Store 应用程序.我通过我的 App.Xaml.vb 播放音乐(以便它可以在我的应用程序中播放并通过 CurrentApp 进行控制).这一切在手机上都很好用.当音乐曲目结束时,会触发 MediaEnded 事件,我的应用程序会选择另一首曲目并播放.在 Windows 8 中,当第一首曲目结束时,应用程序会静音.

I have an app I'm porting from Windows Phone -> Windows 8 Store app. I play music via my App.Xaml.vb (so that it can play throughout my app and be controlled via CurrentApp). This all works great on the phone. When a music track ends, the MediaEnded event is fired and my app chooses another track and plays that. In Windows 8 when the first track ends the app goes silent.

在 Windows 8 上,MediaElement.MediaEnded 事件不会触发.

On Windows 8 the MediaElement.MediaEnded event doesn't fire.

我设置了我的媒体元素并添加了一个处理程序:

I set up my media element and add a handler:

Public WithEvents MusicElement as New MediaElement
[...then in the constructor...]
AddHandler MusicElement.MediaEnded, AddressOf ChangeTrack

音乐播放(使用 PlayMusic 方法,我认为我不需要发布),但是当音乐结束时,事件不会被触发.

The music plays (using a PlayMusic method which I don't think I need to post), but when the music ends the event isn't fired.

手机版和Windows 8版的区别是我不能把MediaElement控件放在Win8的XAML里,因为某种原因——好像是不允许的,所以我在后面的代码中初始化了.

The difference between the phone version and the Windows 8 version is that I can't put the MediaElement control in the XAML in Win8 for some reason - it doesn't seem to be allowed, so I initialise it in my code behind.

我没有使用背景音频"媒体类型(我听说这会导致 MediaEnded 事件出现问题).

I'm not using the 'background audio' media type (which I've heard can cause issues with the MediaEnded event).

我已确认在启动任何播放之前添加了处理程序.

I have confirmed that the handler is added before any playback is initiated.

有什么想法吗?

App.XAML 中的 XAML(尝试)代码:

XAML (attempted) code in App.XAML:

 <Application.Resources>
    <ResourceDictionary>


        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Common/StandardStyles.xaml"/>
            <ResourceDictionary Source="DetectiveStyles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
        <!--<MediaElement x:Name="MusicElement" x:Key="MusicElement" Source="/Sounds/Music/doing-my-best.mp3" AutoPlay="False"/>-->
    </ResourceDictionary>
</Application.Resources>

推荐答案

您的 MediaElement 是否已连接到可视化树?否则,通常不会调用其事件处理程序.

Is your MediaElement hooked up to the Visual Tree? If not, its event handlers generally will not get called.

此外,肯定可以在 Win8 中的 Xaml 中定义 MediaElement,如果您添加一个失败的 Xaml 片段,应该可以找出那里出了什么问题.

Also, it is definitely possible to have MediaElement's defined in Xaml in Win8, if you add a snippet of the Xaml that's failing it should be possible to figure out what's wrong there.

这篇关于MediaElement.MediaEnded 事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆