简体   繁体   English

Xamarin 社区工具包 MediaPlayer 自动播放不起作用?

[英]Xamarin Community Toolkit MediaPlayer AutoPlay doesn't work?

I ran into this issue multiple times but until this current task that I'm doing it didn't worry me too much.我多次遇到这个问题,但直到我正在做的这个当前任务并没有让我太担心。 But now I really need to remove autoplay because this audio must only play on user interaction and not at the beginning of the page load.但现在我真的需要删除自动播放,因为此音频只能在用户交互时播放,而不是在页面加载开始时播放。

MediaPlayer CurrentState property and cannot be changed or assigned on screen loading because it is readonly . MediaPlayer CurrentState属性并且不能在屏幕加载时更改或分配,因为它是readonly的。 This is very annoying and IDK why it is not working.这很烦人,我不知道为什么它不起作用。 AutoPlay="false" and the sound still plays at the start of page loading. AutoPlay="false"并且声音仍然在页面加载开始时播放。

My element is invisible due to it only having to play sound and no one needs to see it.我的元素是不可见的,因为它只需要播放声音而没有人需要看到它。 If you have another way to do this please suggest in the comments and I will try.如果您有其他方法可以做到这一点,请在评论中提出建议,我会尝试。

<xct:MediaElement x:Name="mediaPlayer"
                  Source="{Binding WordSoundSource}"
                  IsVisible="false"
                  AutoPlay="false"/>

Update更新
If I add in my constructor mediaPlayer.Stop() to stop the element from playing at the start then on the play event of a user tapping nothing plays this is extremely annoying.如果我在我的构造函数中添加mediaPlayer.Stop()以停止元素在开始时播放,那么在用户点击任何播放的播放事件时,这非常烦人。

This is how I handle the mediaPlayer.Play() on user tapping an image which has Image.GestureRecognizers && TapGestureRecognizer这就是我在用户点击具有Image.GestureRecognizers && TapGestureRecognizer的图像时处理mediaPlayer.Play()的方式

<Image Source="sound_icon.png"
       VerticalOptions="CenterAndExpand" 
       HorizontalOptions="EndAndExpand"
       HeightRequest="40"
       WidthRequest="40"
       Margin="0, 10, 80, 0">
           <Image.GestureRecognizers>
               <TapGestureRecognizer x:Name="ReplaySound"
                                     NumberOfTapsRequired="1"
                                     Tapped="ReplaySound_Tapped"/>
           </Image.GestureRecognizers>
</Image>
private void ReplaySound_Tapped(object sender, EventArgs e)
{
    if (mediaPlayer.CurrentState == MediaElementState.Stopped || 
       mediaPlayer.CurrentState == MediaElementState.Paused)
    {
        mediaPlayer.Play();
    }
}

There is also a post issues #1715 on GitHub about this being a bug, but it's almost a year ago... Am I wondering if this is the same thing?在 GitHub 上还有一个帖子#1715关于这是一个错误,但差不多一年前了......我想知道这是否是同一回事?

Thanks in advance.提前致谢。

I had this issue last year the only possible way to solve it is setting Speed to 0 by default and then setting it to 1 when you need to play.我去年遇到过这个问题,解决它的唯一可能方法是默认将 Speed 设置为 0,然后在需要播放时将其设置为 1。

<MediaElement 
       x:Name ="vidPlayer"
       Source="ms-appx:///XamarinForms101UsingEmbeddedImages.mp4"
       Speed="0"   
       ShowsPlaybackControls="True"
       .
       . 
       .
        />

and then Change it to 1 when you play:然后在播放时将其更改为 1:

vidPlayer.Speed= 1.0;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么RESX编辑器在Xamarin Studio社区中对我不起作用 - Why doesn't RESX editor work for me in Xamarin Studio Community 导航到另一个视图时出现问题 xamarin 社区工具包 - Problem with navigating to another view xamarin community toolkit Xamarin 社区工具包 InputValidation 连接按钮 - Xamarin Community Toolkit InputValidation connect with button Xamarin 社区工具包弹出MVVM绑定问题 - Xamarin Community Toolkit Popup MVVM Binding Issue Windows Phone工具包本地化不起作用 - Windows Phone Toolkit localization doesn't work Intellisense不适用于MVVM light工具箱 - Intellisense doesn't work for MVVM light toolkit View中的MediaPlayer无法播放。 Xamarin iOS - MediaPlayer in View doesn't play. Xamarin iOS 谁能向我解释如何使用 Func<t, t, bool> ? validateValue = null) Xamarin 社区工具包 ObservableObject 中的验证?</t,> - Can anyone explain to me how I can use Func<T, T, bool>? validateValue = null) validation in the Xamarin Community Toolkit ObservableObject? 尝试使用 MediaPlayer class 播放 a.MP3; 不起作用 - Trying to play a .MP3 using the MediaPlayer class; doesn't work Xamarin 社区工具包 CameraView - 在 Android 上访问 DCIM 文件夹 - Xamarin Community Toolkit CameraView - Access DCIM Folder on Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM