• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Data Stream Playback Issue

New Here ,
Feb 01, 2014 Feb 01, 2014

Copy link to clipboard

Copied

Setup: AMS 5, AIR 3.9, Flex 4.6.0, Windows 7, Flash Builder 4.7

Issue: Given a stream that consists only of data (i.e. NetStream.send() calls), attempting to play it back "instantly" (i.e. with the "reset" value of 2 or 3 which streams all messages at once) doesn't work. It will play back the stream data, but is by no means "all at once," taking many seconds and taking longer as the stream size grows. The messages seem to be sent in bursts with periods of slow arrival reminiscent of normal replay speed.

Below is a simplified example that demonstrates this. When launched, it will send a message to the stream once a second for 30 seconds. Afterwards, buttons are activated that enable "instant" (i.e. reset of 3) replay of messages for the first 10/20/30 seconds of the stream. Watching the console output reveals that the replay is not "instant."

I have tried various workarounds with no success, including calling Stream.send() from the server instead. Changing NetStream.bufferTime seems to have no effect either. Also, a more comlex example of this functionality used to work with FMS 3.5, AIR 1, and Flex 3.1A, so something seems to have either have broken since then or changed such that this is no longer the correct way "instantly" play back a data stream.

I have tried to find other mentions of this issue but found nothing. Any help in understanding and/or working around this issue would be greatly appreciated. Thanks!

Client Code

<?xml version="1.0" encoding="utf-8"?>

<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

                       xmlns:s="library://ns.adobe.com/flex/spark"

                       xmlns:mx="library://ns.adobe.com/flex/mx"

                       applicationActivate="onActivate(event)">

    <fx:Script>

        <![CDATA[

            public function onActivate(event:Event):void

            {

                _client.message = this.message;

                _timer.addEventListener(TimerEvent.TIMER, onTimer);

                _timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);

                _conn.client = _client;

                _conn.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

                _conn.connect("rtmp://localhost:1935/PlaybackTest/_definst_");

            }

            private function onNetStatus(event:NetStatusEvent):void

            {

                switch(event.info.code)

                {

                    case "NetConnection.Connect.Success":

                        // begin publishing

                        _stream = new NetStream(_conn);

                        _stream.bufferTime = 5;

                        _stream.client = _client;

                        _stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

                        _stream.publish("messages", "record");

                        break;

                    case "NetStream.Publish.Start":

                        // start timer to actually publish for 30 seconds

                        _timer.start();

                        break;

                    case "NetStream.Unpublish.Success":

                        // publishing complete: enable playback

                        buttons.enabled = true;

                        break;

                }

            }

            private function onTimer(event:TimerEvent):void

            {

                _stream.send("message", _timer.currentCount);

            }

            private function onTimerComplete(event:TimerEvent):void

            {

                _stream.close();

            }

            public function message(args:*):void

            {

                trace("Call: message(" + args + ")");

            }

            private function play(length:Number):void

            {

                _stream.play("messages", 0, length, 2);

            }

            private var _conn:NetConnection                    = new NetConnection();

            private var _stream:NetStream                    = null;

            private var _client:Object                        = new Object;

            private var _timer:Timer                        = new Timer(1000, 30);

        ]]>

    </fx:Script>

    <s:HGroup id="buttons" enabled="false">

        <s:Button label="10" click="play(10)"/>

        <s:Button label="20" click="play(20)"/>

        <s:Button label="30" click="play(30)"/>

    </s:HGroup>

</s:WindowedApplication>

Server Code (just accepts client connection)

application.onAppStart = function() {}

application.onAppStop = function(info)

{

    return true; //Garbage-collect this app

}

application.onConnect = function(client)

{   

    application.acceptConnection(client);

}

application.onDisconnect = function(client) {}

Views

408

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines