如何在Xamarin Forms中创建LibVLCSharp自定义播放控件? [英] How to create LibVLCSharp custom playback controls in Xamarin Forms?

查看:220
本文介绍了如何在Xamarin Forms中创建LibVLCSharp自定义播放控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找有关如何为所有人似乎都在谈论的LibVLCSharp创建自定义播放控件的指南,这是我从未找到的向导.

I've been searching for days now for a guide on how to create the custom playback controls for LibVLCSharp that everyone seems to talk about, which I never found a guid for.

我只是想为底部的播放控制面板创建带有事件处理程序的其他按钮,我尝试了此操作,但是在进入中断模式时在启动时抛出了 System.NullReferenceException 异常...

I simply want to create other buttons with event handlers for the bottom playback control panel, I tried this but throws a System.NullReferenceException exception on startup while getting into break mode...

<vlc:MediaPlayerElement MediaPlayer="{Binding MediaPlayer}" LibVLC="{Binding LibVLC}">
    <vlc:MediaPlayerElement.PlaybackControls>
        <vlc:PlaybackControls>
            <vlc:PlaybackControls.ControlTemplate>
                <ControlTemplate>
                    <Grid>
                        <StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
                            <Button Grid.Column="0" Text="Test 1"/>
                            <Button Grid.Column="1" Text="Test 1"/>
                            <Button Grid.Column="2" Text="Test 1"/>
                        </StackLayout>
                    </Grid>
                </ControlTemplate>
            </vlc:PlaybackControls.ControlTemplate>
        </vlc:PlaybackControls>
    </vlc:MediaPlayerElement.PlaybackControls>
</vlc:MediaPlayerElement>

我希望它的行为与原始行为相同(自动隐藏,点击时叠加等),但是具有自己的布局和控件.我还考虑过使用现有的按钮,并尝试覆盖其处理程序以实现我自己的代码,并覆盖每个按钮的text属性以更改其图标,但没有找到任何帮助的运气.

I want it to act just like the original one (Auto hides, overlays on tapping, etc...) but with my own layout and controls. I also thought about using the existing one and try to override their handler to implement my own code and override the text property for each button to change its icon but no luck of finding any help.

预先感谢^ _ ^

推荐答案

我终于发现了产生异常的问题,当我创建完全正确的自定义控件模板时,由LibVLCSharp开发人员自己提供的MediaPlayerElement代码本身无法找到带有名称已经定义,因为它们使用按钮和视图的硬编码名称,而不是使用绑定和动态设置器.

I finally found the problem which was making exceptions, when I create custom control template which completely correct, the MediaPlayerElement code behind by LibVLCSharp developers itself cannot find the elements with the names defined anymore as they used hardcoded names for the buttons and views instead of using bindings and dynamic setters.

因此,可以采取几种解决方法来解决此问题,这是我的一些想法:

Thus, several workarounds could be made to fix such issue, here are some of my ideas:

  1. 使用通用样式
  1. Use the generic style documented here and modify it without removing any elements but rather hide them out or overlay them.
  2. Create your own style with controls obtaining the same names of the original ones.
  3. Find a way to modify or maybe create a whole new playback control element using the original one which can be found here and here.

感谢 mfkl 的答案,该答案帮助我了解了一切背后的工作原理,并提出了解释,尽管这花了我几天的时间.

Thanks to mfkl's answer which helped me find out how everything worked under the hood to come up with the explaination, even though this took me a couple of days to figure out.

这篇关于如何在Xamarin Forms中创建LibVLCSharp自定义播放控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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