Highlighted

NetStreamAppendBytesAction.RESET_BEGIN

Community Beginner ,
Apr 03, 2019

Copy link to clipboard

Copied

package ActionScript.Model.video_module {

import flash.display.Sprite;

import flash.events.Event;

import flash.utils.ByteArray;

import flash.events.*;

import flash.media.Video;

import flash.display.Sprite;

import flash.net.*;

import ActionScript.Model.CustomEvent;

public class LocalVideoPlayer extends Sprite {

private var url: String = "";

private var _vidXmax: Number = 0;

private var _vidYmax: Number = 0;

private var _main_nc: NetConnection = new NetConnection();

private var serverLoc: String = null;

private var videoBa: ByteArray = null;

private var _ns: NetStream;

private var ns: NetStream;

private var _video: Video;

private var urlLoad: URLLoader;

private var _totalTime: Number = 0;

private var _vidWidth: Number;

private var _vidHeight: Number;

public function LocalVideoPlayer(_url: String, _width: Number = 1024, _height: Number = 768) {

url = _url;

_vidXmax = _width;

_vidYmax = _height;

_main_nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

_main_nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

_main_nc.connect(serverLoc);

}

private function LoadVideo(): void {

urlLoad = new URLLoader();

urlLoad.dataFormat = URLLoaderDataFormat.BINARY;

urlLoad.load(new URLRequest(url))

urlLoad.addEventListener(Event.COMPLETE, onComplete_func);

}

private function onComplete_func(e: Event): void {

var urlLoader1: URLLoader = e.target as URLLoader;

videoBa = urlLoader1.data;

connectStream();

}

private function onNetStatus(event: Object): void {

switch (event.info.code) {

case "NetConnection.Connect.Success":

LoadVideo();

break;

case "NetStream.Play.StreamNotFound":

break;

case "NetStream.Play.Stop":

break;

case "NetStream.Buffer.Empty":

onseek()

break;

case "NetStream.Buffer.Full":

onReady();

break;

case "NetStream.Buffer.Flush":

break;

case "NetStream.Seek.Complete":

break;

}

}

private function onReady():void{

var evt:CustomEvent=new CustomEvent(CustomEvent.READY_VIDEO);

this.dispatchEvent(evt);

}

private function onComplete():void{

var evt:CustomEvent=new CustomEvent(CustomEvent.VIDEO_FINISH);

this.dispatchEvent(evt);

}

public function  onseek():void{

_ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);

_ns.appendBytes(videoBa);

}

public function onresume():void{

_ns.resume();

this.addEventListener(Event.ENTER_FRAME,onListener);

}

private function onListener(e:Event):void{

trace(_ns.time)

}

private function securityErrorHandler(event: SecurityErrorEvent): void {

trace("securityErrorHandler: " + event);

}

private function asyncErrorHandler(event: AsyncErrorEvent): void {

trace(event.text);

}

private function connectStream(): void {

_ns = new NetStream(_main_nc);

_ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);

_ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

var custom_obj: Object = new Object();

_ns.useHardwareDecoder = true;

custom_obj.onMetaData = onMetaDataHandler;

custom_obj.onCuePoint = onCuePointHandler;

_ns.client = custom_obj;

_ns.play(null);

_video = new Video(_vidXmax, _vidYmax);

_video.attachNetStream(_ns);

_video.smoothing = true;

_video.addEventListener(VideoEvent.RENDER_STATE, videoStateChange);

addChild(_video);

_ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);

_ns.appendBytes(videoBa);

_ns.pause();

}

private function onMetaDataHandler(metaInfoObj: Object): void {

if (_vidXmax != metaInfoObj.width) {

_video.width = metaInfoObj.width;

_vidWidth = metaInfoObj.width;

_video.height = metaInfoObj.height;

_vidHeight = metaInfoObj.height;

}

_totalTime = metaInfoObj.duration;

_ns.bufferTime = 0;

}

private function onCuePointHandler(cueInfoObj: Object): void {

trace("cuepoint: time=" + cueInfoObj.time + " name=" + 

cueInfoObj.name + " type=" + cueInfoObj.type);

}

private function videoStateChange(e: VideoEvent): void {

trace(String(_ns.useHardwareDecoder)+"\n"+e.status);

}

}

}

//

when video play end,exec "onseek()" ,Caton happened??????

_ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);

_ns.appendBytes(videoBa);

thanks

TOPICS
Development

Views

285

Likes

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

NetStreamAppendBytesAction.RESET_BEGIN

Community Beginner ,
Apr 03, 2019

Copy link to clipboard

Copied

package ActionScript.Model.video_module {

import flash.display.Sprite;

import flash.events.Event;

import flash.utils.ByteArray;

import flash.events.*;

import flash.media.Video;

import flash.display.Sprite;

import flash.net.*;

import ActionScript.Model.CustomEvent;

public class LocalVideoPlayer extends Sprite {

private var url: String = "";

private var _vidXmax: Number = 0;

private var _vidYmax: Number = 0;

private var _main_nc: NetConnection = new NetConnection();

private var serverLoc: String = null;

private var videoBa: ByteArray = null;

private var _ns: NetStream;

private var ns: NetStream;

private var _video: Video;

private var urlLoad: URLLoader;

private var _totalTime: Number = 0;

private var _vidWidth: Number;

private var _vidHeight: Number;

public function LocalVideoPlayer(_url: String, _width: Number = 1024, _height: Number = 768) {

url = _url;

_vidXmax = _width;

_vidYmax = _height;

_main_nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

_main_nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

_main_nc.connect(serverLoc);

}

private function LoadVideo(): void {

urlLoad = new URLLoader();

urlLoad.dataFormat = URLLoaderDataFormat.BINARY;

urlLoad.load(new URLRequest(url))

urlLoad.addEventListener(Event.COMPLETE, onComplete_func);

}

private function onComplete_func(e: Event): void {

var urlLoader1: URLLoader = e.target as URLLoader;

videoBa = urlLoader1.data;

connectStream();

}

private function onNetStatus(event: Object): void {

switch (event.info.code) {

case "NetConnection.Connect.Success":

LoadVideo();

break;

case "NetStream.Play.StreamNotFound":

break;

case "NetStream.Play.Stop":

break;

case "NetStream.Buffer.Empty":

onseek()

break;

case "NetStream.Buffer.Full":

onReady();

break;

case "NetStream.Buffer.Flush":

break;

case "NetStream.Seek.Complete":

break;

}

}

private function onReady():void{

var evt:CustomEvent=new CustomEvent(CustomEvent.READY_VIDEO);

this.dispatchEvent(evt);

}

private function onComplete():void{

var evt:CustomEvent=new CustomEvent(CustomEvent.VIDEO_FINISH);

this.dispatchEvent(evt);

}

public function  onseek():void{

_ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);

_ns.appendBytes(videoBa);

}

public function onresume():void{

_ns.resume();

this.addEventListener(Event.ENTER_FRAME,onListener);

}

private function onListener(e:Event):void{

trace(_ns.time)

}

private function securityErrorHandler(event: SecurityErrorEvent): void {

trace("securityErrorHandler: " + event);

}

private function asyncErrorHandler(event: AsyncErrorEvent): void {

trace(event.text);

}

private function connectStream(): void {

_ns = new NetStream(_main_nc);

_ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);

_ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

var custom_obj: Object = new Object();

_ns.useHardwareDecoder = true;

custom_obj.onMetaData = onMetaDataHandler;

custom_obj.onCuePoint = onCuePointHandler;

_ns.client = custom_obj;

_ns.play(null);

_video = new Video(_vidXmax, _vidYmax);

_video.attachNetStream(_ns);

_video.smoothing = true;

_video.addEventListener(VideoEvent.RENDER_STATE, videoStateChange);

addChild(_video);

_ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);

_ns.appendBytes(videoBa);

_ns.pause();

}

private function onMetaDataHandler(metaInfoObj: Object): void {

if (_vidXmax != metaInfoObj.width) {

_video.width = metaInfoObj.width;

_vidWidth = metaInfoObj.width;

_video.height = metaInfoObj.height;

_vidHeight = metaInfoObj.height;

}

_totalTime = metaInfoObj.duration;

_ns.bufferTime = 0;

}

private function onCuePointHandler(cueInfoObj: Object): void {

trace("cuepoint: time=" + cueInfoObj.time + " name=" + 

cueInfoObj.name + " type=" + cueInfoObj.type);

}

private function videoStateChange(e: VideoEvent): void {

trace(String(_ns.useHardwareDecoder)+"\n"+e.status);

}

}

}

//

when video play end,exec "onseek()" ,Caton happened??????

_ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);

_ns.appendBytes(videoBa);

thanks

TOPICS
Development

Views

286

Likes

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
Apr 03, 2019 0

Have something to add?

Join the conversation