0

A Video player is created using "Video" in flash action script 3.0. And played video using net stream. The sample code is:

connection = new NetConnection();
connection.connect(null);

on connection success stream and video crested and played.

stream = new NetStream(connection);
video = new Video();
video.width = stage.stageWidth;
video.height = stage.stageHeight;
video.attachNetStream(stream);

stream.play(videoURL);

Video is playing correctly. I want to display subtitle for the video. I have .srt formeted file for the video, any solution in as3 to load the SRT for the Video on flash.

sureshunivers
  • 1,753
  • 12
  • 27
  • write your own parser. – BotMaster Jul 13 '15 at 13:08
  • 1
    Have you looked at SRT inside Notepad? Its just text file with timecodes and relevant text. You could **[Google search](https://www.google.co.uk/?gws_rd=cr&ei=nqYkUqj1Osi20QXAhoHoDQ#q=as3+srt+parser)** for an AS3 based SRT file parser or else do it yourself by just keep track of video timecode and use enterFrame to check if video_timecode == expected_SRT_Text_time (as time-coded in SRT file) and display such text.. – VC.One Jul 13 '15 at 20:25

1 Answers1

1

Writing a .srt parser isn't that difficult. Use the CuePoint API provided by AS3 to add cuepoints to your Video instance at runtime. Then listen for the onCuePoint event and display the relevant text in a text field.

var nc:NetConnection = new NetConnection(); 
nc.connect(null); 

var ns:NetStream = new NetStream(nc); 
var client = {};
client.onCuePoint = function(info:Object):void
{
    var key:String; 
    for (key in info) 
    { 
        trace(key + ": " + info[key]); 
    }
};
ns.client = client;

var vid:Video = new Video(); 
vid.attachNetStream(ns); 
addChild(vid);
ns.play("video.flv");

Instead of tracing the output, you can display text in an on-screen text field.

Pranav Negandhi
  • 1,594
  • 1
  • 8
  • 17