Forums: Flash:

 

as3 cue points

first
 

JLM as3 cue points

I was trying to do subtitles without using a component and after reading, some copy and paste and some thought I ended up with the following code, which gets the meta data but does not seem to be grabbing the subtitles from the video, feel free to crit but I am rather a newbie to as3.


package
{


import flash.display.*;
import flash.text.*;
import flash.events.*;

import flash.media.Video;

import net.justinfront.SubtitleClient;
import net.justinfront.VideoPlayer;


public class VideoCueTest extends Sprite
{


private var _content_txt: TextField;
private var _videoPlayer: VideoPlayer;
private var _onStageVideo: Video;

private var _testVideo: String = "videos/testVideo.flv";


public function VideoCueTest()
{

trace( 'VideoCueTest' );

init();

}


private function init():void
{

_onStageVideo = this._vid;
_content_txt = this.content_txt;
_videoPlayer = new VideoPlayer();
this._but.addEventListener( MouseEvent.CLICK, chooseVideo );

}


private function chooseVideo( e: Event ):void
{

trace( e );

var flv: String = _testVideo;

playVideo( flv );

}


private function playVideo( vid_: String ):void
{

_videoPlayer.setVideo( _onStageVideo, vid_, _content_txt );
_videoPlayer.play();

}


}


}


package net.justinfront
{

import flash.text.*;

public class SubtitleClient
{


private var _txt: TextField;


public function SubtitleClient( txt_: TextField )
{

_txt = txt_;

}


public function onCuePoint( infoObject: Object ):void
{

trace( "onCuePoint" );
_txt.appendText( 'cuePoint: ' + infoObject.info.code +'\n' );

}


public function onMetaData( infoObject: Object ):void
{

var all: String;

_txt.appendText( 'onMetaData\n\n' );

for( all in infoObject )
{

_txt.appendText( all + ' : ' + infoObject[ all ] +'\n')

}


}

}

}


package net.justinfront
{


import net.justinfront.SubtitleClient;
import flash.events.*;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.net.*;
import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.media.SoundChannel;
import flash.media.SoundMixer;

public class VideoPlayer extends EventDispatcher
{

public static var STARTED: String = 'started';

private var _vid: Video;
private var _nc: NetConnection;
private var _ns: NetStream;
private var _txt: TextField;
private var _flv: String;

public function VideoPlayer()
{

}


public function setVideo( vid_: Video, flv_: String, txt_: TextField )
{

_flv = flv_;
_vid = vid_;
_txt = txt_;
init();

}


private function init()
{

_nc = new NetConnection();

_nc.addEventListener( NetStatusEvent.NET_STATUS, netStatusHandler );
_nc.addEventListener( SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler );

_nc.connect(null);

}


public function play()
{

_ns.play( _flv );
dispatchEvent( new Event( VideoPlayer.STARTED ) );

}


public function stop()
{

//_ns.stop();??
SoundMixer.stopAll();

}


private function netStatusHandler( event: NetStatusEvent ):void
{

switch ( event.info.code )
{

case "NetConnection.Connect.Success":
connectStream();
break;

case "NetStream.Play.StreamNotFound":
trace( "Unable to locate video: " + _flv );
break;

}

}


private function connectStream():void
{

_ns = new NetStream( _nc );
_ns.addEventListener( NetStatusEvent.NET_STATUS, netStatusHandler );
_ns.addEventListener( AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler );
_ns.client = new SubtitleClient( _txt );
_vid.attachNetStream( _ns );

}


private function securityErrorHandler(event:SecurityErrorEvent):void
{

trace("securityErrorHandler: " + event);

}


private function asyncErrorHandler(event:AsyncErrorEvent):void
{

// ignore AsyncErrorEvent events.

}

}

}








 

Storm

Can you post the .flv?

Are you getting nothing at all? Try the onCuePoint function in VideoPlayer.as and call it:
ns.client = { onMetaData:ns_onMetaData, onCuePoint:ns_onCuePoint };

I don't think it's calling the onCuePoint function at all.

 

JLM

There are a couple of things on the stage, I am not creating them dynamically because they are to access pv stuff and so easy to have them as stage for mo.

_vid (video)
content_txt (textfield)
_but (movieclip)


I have been fiddling with xml separately and that is going welland I have not put the subtiltes in this code, at the moment I just wanted cue points to trace out ie 1,2,3 or something anything I can cross refer to.

 

JLM

Storm

oops I downloaded the video from the link (adobe.com/devnet/flash/articles/flvplayback_programming.html)

and my code is working fine, I had tried it with two lots that I thought (had been told) had cuePoints but they seem not to or maybe they are not in the right format. Anyways the code above works, if anyone needs the test fla for the as I created above let me know. Normally I would have tried that video you posted straight away but the as3 is on the side from an as2 project that currently seems to be draining my life so I am trying to fit this as3 round it and as a result I do silly things like starting posts when my codes working!!

 

Storm

nice work sherlock

 

JLM

Update


public function onCuePoint( infoObject: Object ):void
{
trace( "onCuePoint" + infoObject.name);
// need to get data out of class here... to be continued
}

 
first
 

Forums: Flash: as3 cue points

 
New Post
 
You must be logged in to post