samedi 30 mai 2015

As3 Flash video control with swipe gestures

This is for a flash app running on a windows touch based system. When swf is loaded video should play normally when user touches the screen video stops, if user drags finger right video plays forward. If user drags finger left video plays backwards.

Here is my code-

import fl.motion.MotionEvent;
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.events.Event;
import flash.events.FullScreenEvent;
import flash.geom.Rectangle;

var tapped = "false";
var _mouseClicked:Boolean = false;


Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onTouchBegin);
stage.addEventListener(MouseEvent.MOUSE_UP, onTouchEnd);
stage.addEventListener(MouseEvent.CLICK, onTouchClick);

function onTouchClick(evt:Event)
{
    timer.stop();
    if (tapped == "false")
    {
        tapped = "true";
        ns.pause();
        trace("movie stopped");
    }
    else
    {
        tapped = "false";
        ns.resume();
        trace("movie played");
    }
}



var curX:int = 0;
var prevX:int = 0;



function onTouchBegin(evt:Event)
{
    _mouseClicked = true;
    ns.pause();
}



function onTouchEnd(evt:Event)
{
    _mouseClicked = false;
}



function enterFrameHandler(event:Event):void
{
    if (_mouseClicked)
    {
        prevX = curX;
        curX = stage.mouseX;
        if (curX < prevX)
        {
            ns.seek(ns.time -1);

        }
        if (curX > prevX)
        {
            ns.seek(ns.time +1);
        }
    }
    else
    {
        //trace(curX);
    }
}

var nc:NetConnection = new NetConnection();
nc.connect(null);

var ns:NetStream = new NetStream(nc);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
ns.play("myVideo.flv");
function asyncErrorHandler(event:AsyncErrorEvent):void
{
    // ignore error 
}

var myVid:Video = new Video();
myVid.attachNetStream(ns);
addChild(myVid);

I am facing 2 problems here. 1. Its forwarding jumpy like 1 second but I want it very smooth like panoramic style 2. Its really really frustrating that the backward is not working for high quality HD videos.

Someone please help. Thanks

Aucun commentaire:

Enregistrer un commentaire