Adobe FLA: автоигра - PullRequest
       6

Adobe FLA: автоигра

0 голосов
/ 29 марта 2011

Я ОЧЕНЬ новичок в разработке Flash Actionscript и унаследовал скрипт, который запускает воспроизведение веб-потока, когда пользователь нажимает кнопку play.

Я перешел к действию и щелкнул правой кнопкой мыши, Действия.Этот код ниже появился.Я пытаюсь добиться того, чтобы поток воспроизводился сразу после загрузки объекта (но затем пользователь должен иметь возможность нажать кнопку, чтобы остановить поток (его плата за минуту)

Может кто-нибудьНаправь меня в правильном направлении. Код, который может быть на триггере или где-то еще, это все, что я смог найти.

Редактировать ИСПРАВЛЕНО:

var nc:NetConnection = null;
var nsPlay:NetStream = null;                      


var myQueryStrings=this.loaderInfo.parameters;
var user_id:String = myQueryStrings.user_id;
var site_id:String = myQueryStrings.site_id;
var stream_id:String = myQueryStrings.stream_id;
var RTMP:String = "rtmp://" + myQueryStrings.rtmp + "?" + user_id + "-" + site_id + "-" + stream_id;
var stream_query:String = stream_id + "?" + user_id + "-" + site_id + "-" + stream_id;


function ncOnStatus(infoObject:NetStatusEvent) {
   switch (infoObject.info.code) {
       case "NetConnection.Connect.Success":
           _doPlay();
           break;
       case "NetStream.Play.StreamNotFound":
           trace("Unable to locate video");
        break;
   }
}


function doConnect() {
    trace("doConnect");

    // connect to the Wowza Media Server
    if (nc == null) {
        trace("nc is null");
        // create a connection to the wowza media server
        nc = new NetConnection();
        nc.connect(RTMP);

        // get status information from the NetConnection object
        nc.addEventListener(NetStatusEvent.NET_STATUS, ncOnStatus);
        doSubscribe.addEventListener(MouseEvent.CLICK, subscribe);
        doSubscribe.label = 'Stop';//Rename your btn to Stop
    } else {
        trace("nc not null");
        nsPlay = null;
        videoRemote.attachNetStream(null);
        videoRemote.clear();
        nc.close();
        nc = null;
        prompt.text = "";
    }
}



function nsPlayOnStatus(infoObject:NetStatusEvent) {
    trace("nsPlay: "+infoObject.info.code+" ("+infoObject.info.description+")");
    if (infoObject.info.code == "NetStream.Play.StreamNotFound" || infoObject.info.code == "NetStream.Play.Failed")
        prompt.text = infoObject.info.description;
}


function subscribe(event:MouseEvent) {
    trace("subscribe");

    if (doSubscribe.label == 'Play') {
        _doPlay();//moved code into a method so you can call it on load
    } else {       
        // here we are shutting down the connection to the server
        videoRemote.attachNetStream(null);
        nsPlay.play(null);
        nsPlay.close();

        doSubscribe.label = 'Play';
    }
}


function nsPublishOnStatus(infoObject:NetStatusEvent) {
    trace("nsPublish: "+infoObject.info.code+" ("+infoObject.info.description+")");
    if (infoObject.info.code == "NetStream.Play.StreamNotFound" || infoObject.info.code == "NetStream.Play.Failed")
        prompt.text = infoObject.info.description;
}


function _doPlay():void {
    // create a new NetStream object for video playback
        trace("do play");
        trace(nc);
        nsPlay = new NetStream(nc);

        // trace the NetStream status information
        nsPlay.addEventListener(NetStatusEvent.NET_STATUS, nsPlayOnStatus);

        var nsPlayClientObj:Object = new Object();
        nsPlay.client = nsPlayClientObj;
        nsPlayClientObj.onMetaData = function(infoObject:Object) 
        {
            trace("onMetaData");

            // print debug information about the metaData
            for (var propName:String in infoObject)
            {
                trace("  "+propName + " = " + infoObject[propName]);

                if (propName == "CameraWidth") { videoRemote.width = infoObject["CameraWidth"]; }
                if (propName == "CameraHeight") { videoRemote.height = infoObject["CameraHeight"]; }
            }
        };      

        // set the buffer time to zero since it is chat
        nsPlay.bufferTime = 0;

        // subscribe to the named stream
        nsPlay.play(stream_query);

        //prompt.text = stream_query;

        // attach to the stream
        videoRemote.attachNetStream(nsPlay);

        doSubscribe.label = 'Stop';
}


stage.align = "TL";
stage.scaleMode = "noScale";


doConnect();
stop();

1 Ответ

0 голосов
/ 29 марта 2011

Вы можете попробовать это:

var nc:NetConnection = null;
var nsPlay:NetStream = null;                      

//get var from flash page
var myQueryStrings=this.loaderInfo.parameters;
var user_id:String = myQueryStrings.user_id;
var site_id:String = myQueryStrings.site_id;
var stream_id:String = myQueryStrings.stream_id;
var RTMP:String = "rtmp://" + myQueryStrings.rtmp + "?" + user_id + "-" + site_id + "-" + stream_id;
var stream_query:String = stream_id + "?" + user_id + "-" + site_id + "-" + stream_id;

function ncOnStatus(infoObject:NetStatusEvent)
{
    trace("nc: "+infoObject.info.code+" ("+infoObject.info.description+")");
    if (infoObject.info.code == "NetConnection.Connect.Failed")
        prompt.text = "Connection failed: please refresh the page and try again";
    else if (infoObject.info.code == "NetConnection.Connect.Rejected")
        prompt.text = infoObject.info.description;
}

function doConnect()
{
    // connect to the Wowza Media Server
    if (nc == null)
    {
        // create a connection to the wowza media server
        nc = new NetConnection();
        nc.connect(RTMP);

        // get status information from the NetConnection object
        nc.addEventListener(NetStatusEvent.NET_STATUS, ncOnStatus);

        doSubscribe.addEventListener(MouseEvent.CLICK, subscribe);
        //doSubscribe.label = 'Play';
        doSubscribe.label = 'Stop';//Rename your btn to Stop
        _doPlay();//fire the video
        //prompt.text = RTMP;
    }
    else
    {
        nsPlay = null;

        videoRemote.attachNetStream(null);
        videoRemote.clear();

        nc.close();
        nc = null;

        prompt.text = "";
    }
}



function nsPlayOnStatus(infoObject:NetStatusEvent)
{
    trace("nsPlay: "+infoObject.info.code+" ("+infoObject.info.description+")");
    if (infoObject.info.code == "NetStream.Play.StreamNotFound" || infoObject.info.code == "NetStream.Play.Failed")
        prompt.text = infoObject.info.description;
}

function subscribe(event:MouseEvent)
{
    if (doSubscribe.label == 'Play')
    {
        _doPlay();//moved code into a method so you can call it on load
    }
    else
    {       
        // here we are shutting down the connection to the server
        videoRemote.attachNetStream(null);
        nsPlay.play(null);
        nsPlay.close();

        doSubscribe.label = 'Play';
    }
}

function nsPublishOnStatus(infoObject:NetStatusEvent)
{
    trace("nsPublish: "+infoObject.info.code+" ("+infoObject.info.description+")");
    if (infoObject.info.code == "NetStream.Play.StreamNotFound" || infoObject.info.code == "NetStream.Play.Failed")
        prompt.text = infoObject.info.description;
}

function _doPlay():void {
    // create a new NetStream object for video playback
        nsPlay = new NetStream(nc);

        // trace the NetStream status information
        nsPlay.addEventListener(NetStatusEvent.NET_STATUS, nsPlayOnStatus);

        var nsPlayClientObj:Object = new Object();
        nsPlay.client = nsPlayClientObj;
        nsPlayClientObj.onMetaData = function(infoObject:Object) 
        {
            trace("onMetaData");

            // print debug information about the metaData
            for (var propName:String in infoObject)
            {
                trace("  "+propName + " = " + infoObject[propName]);

                if (propName == "CameraWidth") { videoRemote.width = infoObject["CameraWidth"]; }
                if (propName == "CameraHeight") { videoRemote.height = infoObject["CameraHeight"]; }
            }
        };      

        // set the buffer time to zero since it is chat
        nsPlay.bufferTime = 0;

        // subscribe to the named stream
        nsPlay.play(stream_query);

        //prompt.text = stream_query;

        // attach to the stream
        videoRemote.attachNetStream(nsPlay);

        doSubscribe.label = 'Stop';
}

stage.align = "TL";
stage.scaleMode = "noScale";

doConnect();
stop();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...