Copy link to clipboard
Copied
I'm writing On-demand player. This player need to play flv or f4v format videos.
Example: In that vod folder will available 1 video file (that is flv or f4v), I don't know what is that file format.
So first how can i check that the file format flv or f4v?
I'm trying to below like this.But this is not correct & not working. Can you suggest me how can i play or how to know video file extension?
var videoURL:String;
var videoFileName:String = "test";
var f4v:Boolean = true;
var prefix1:String = "mp4";
var prefix2:String = "f4v";
if(f4v == true)
{
videoURL = prefix1 + ":" + videoFileName + "." + prefix2;
trace("F4V OK");
// trace(videoURL);
}
else{
videoURL = videoFileName;
trace("FLV OK");
}
var serverURL:String = "rtmp://192.168.1.5/vod/";
var nConnection:NetConnection;
var ns:NetStream;
var video:Video = new Video();
nConnection = new NetConnection();
nConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
nConnection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, ayncErrorHandler);
nConnection.connect(serverURL);
function netStatusHandler(event:NetStatusEvent):void
{
trace(event.info.code);
switch (event.info.code)
{
case "NetConnection.Connect.Success" :
connectStream();
break;
case "NetConnection.Connect.Failed" :
break;
case "NetStream.Play.StreamNotFound" :
trace("Stream not found: ");
break;
case "NetStream.Play.Start" :
trace("Play Started");
break;
case "NetStream.Play.Stop" :
break;
default :
}
}
function connectStream():void
{
ns = new NetStream(nConnection);
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, ayncErrorHandler);
ns.client = this;
vidDisplay.attachNetStream(ns);
ns.play(videoURL);
vidDisplay.smoothing = true;
}
function securityErrorHandler(event:SecurityErrorEvent):void
{
trace("securityErrorHandler: " + event);
}
function ayncErrorHandler(event: AsyncErrorEvent):void
{
}
Copy link to clipboard
Copied
What is setting videoFileName? Also you're setting a f4v:Boolean = true; assignment above and I don't see any logic to alter this in the case it's FLV so it will always assume the video is f4v unless "something else" is changing it.
To determine between F4V and FLV you really only need to look at the files extension. You can set your bool based on that.
var f4v:Boolean = videoFileURL.toUpperCase().indexOf('.F4V') != -1 ? true : false;
Then actually run your check
if (f4v)
{
// handle f4v
}
else
{
// handle FLV
}
Or use a switch if you're handling more than just these two.. Something like:
var sourceURL:String;
switch (videoFileURL.toUpperCase().substr(-3,3))
{
case "MP4":
// code to set sourceURL to MP4...
break;
case "FLV":
// code to set sourceURL to FLV...
break;
case "F4V":
// code to set sourceURL to F4V...
break;
default:
// perhaps a default to one of the formats..
}
If you're actually trying to load the file and determine if the extension is incorrect then you'd have to use your errors during load and attempt alternate loads until you achieve a successful load. Metadata has an ID for the codec (audio/video) as well.
Copy link to clipboard
Copied
Thank you for your replay.
above example code will work with http streaming.
Flash player playing flv video without extension (RTMP Stream)
Flash player playing flv video with extension (HTTP Stream)
Present .net passing only filename (video) not (video.flv) to my flash player.
in the application folder there is 1 file available that is flv or f4v (it may be flv or it maybe f4v). But file name is same.
In this scenario how can i recognize file extension?
Copy link to clipboard
Copied
If the file you're being told to play lacks an extension that's about as much information that you can know about the file before attempting to play it. Otherwise you'll need to make a connection and request to file to get more information on it.
In a live stream you can send use the setDataFrame directive to send metadata. Is your server sending any metadata? That could be used to relay the info and determine what video source. At that point you've alreaday made the connection and it may simply require you connecting twice if you determine it's a F4V instead of FLV, or vice versa, so you can reconnect using a different method if you choose.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now