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.
}
}
}