如何使用触摸事件在MediaElement中播放和暂停视频 [英] How to play and pause a video in MediaElement with touch events

查看:299
本文介绍了如何使用触摸事件在MediaElement中播放和暂停视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ScatterViewItem中的视频。当我进行简单的触摸(如鼠标点击)时,它会播放或暂停,但我希望能够在每次开始新的拖动操作时都不会触发此事件。

I have a video that is in a ScatterViewItem. When I make a simple touch (like a mouse click) it plays or pauses, but I want to be able to drag it around without firing this event everytime I start a new drag operation.

我的想法是捕获touchUp和touchMove事件,我有一个标志来控制用户在touchMove事件中的touchUp事件之前拖动对象。在代码中是这样的:

My idea is to capture the touchUp and touchMove events, and I have a flag to control wether the user has dragged the object before the touchUp event inside the touchMove event. In code is something like this:

bool touchMove = false;

private void touchUp(object sender, TouchEventArgs e) {
	if (!touchMove) {
		scatterVideo.Play()/Pause();
		touchMove = false;
	}
}

private void touchMove(object sender, TouchEventArgs e) {
	if (!touchMove) {
		touchMove = true;
	}
}

我的问题是我不能同时发射任何事件。我也尝试过使用PreviewTouchUp和PreviewTouchMove,但这些都没有被触发。

My problem is that I can't fire neither events. I also tried with the PreviewTouchUp and PreviewTouchMove and neither of those are triggered.

所以我的问题是:表面上的手指对象有什么事件可以触发TouchUp(当我从桌子上抬起手指)和TouchMove(当我在TouchDown后移动时)?

So my question is: What are the events, to the finger object on the surface, to trigger TouchUp (when I raise the finger from the table) and TouchMove (when I move around after I TouchDown)?

你不担心_blank ...让我担心_blank!

Don't you worry about _blank... let me worry about _blank!

推荐答案

Hello jose,

Hello jose,

我觉得你做的有点儿复杂。

I think you make things a little bit complicated.

最好的方法是构建一个自定义控件调用VideoControl。

The best approach would be to build a custom control calls VideoControl.

在该控件中定义2个ContentControl对象:一个将接收一个媒体元素第二个将收到一个UniforGrid,例如带有播放 - 暂停 - 停止按钮集合。

In that control you define 2 ContentControl object : One will receive a media element and the second one will receive a UniforGrid for instance with Play-pause-Stop buttons collection.

然后当你构建scatterviewitem时,内容proeprty将设置为VideoControl

Then when you build you scatterviewitem, the content proeprty will be set to the VideoControl

approch将更加模块化,你可以自由移动散点图,而不会通过按钮层干扰对视频的控制。

The approch will be then more modular and you will be able to freely move the scatterview without disturbing the control of the video by the buttons layer.

Hope它有帮助

问候

哔叽


这篇关于如何使用触摸事件在MediaElement中播放和暂停视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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