I want to play an flv video file in my website. The video will be started playing considering the internet connection speed of client machine so that the video will never pause showing the loading image for buffering.
Either the buffering/streaming will be completed first then play or the video will start playing after a short delay while buffering will be done e.g. 40% and rest of buffering will go simultaneously so that the video will neve开发者_JAVA技巧r pause and show the loading image.
How to accomplish this? Is it possible to implement?
Please help to implement this.
One thing that can really help you out is to encode the video at different bitrates. There's no getting around the fact that some people will simply have insufficient bandwidth to have consistently good video playback. Fortunately, Flash allows you to do dynamic stream switching based on the detected client bandwidth. To utilize this feature, rather than playing an FLV directly, you give the player a SMIL file playlist with the different streams listed. FLVPlayback has this functionality built in. Here's a sample SMIL file, stolen from here:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE smil PUBLIC "-//W3C//DTD SMIL 2.0//EN"
"http://www.w3.org/2001/SMIL20/SMIL20.dtd">
<smil xmlns="http://www.w3.org/2001/SMIL20/Language">
<body>
<switch>
<video src="video2.flv" system-bitrate="512000" />
<video src="video1.flv" system-bitrate="256000" />
<video src="video0.flv" />
</switch>
</body>
</smil>
You should read the Eight Fallacies of Distributed Computing [wikipedia]. "All prove to be false in the long run and all cause big trouble and painful learning experiences."
Briefly:
- Constant/fixed speed isn't.
- Reliable networks aren't.
This is the basis of much of computers, in fact, they are abstractions on lower level concepts. And this is a Good Thing(tm), because it allows us to get more work done; it becomes a problem when the abstractions leak.
Where am I going with this? You can't know you'll never need to show a buffering window just because the initial part of the movie loaded in X amount of time. Sure, most of the time you can measure that and get decent results, but every once in a while a child will pull a ethernet cable out of a socket—figuratively or literally. And you don't want to crash or otherwise lose a user's data when that happens.
The solution is easy: design your setup so most users don't see the buffering window, but don't try to prevent it when it's needed.
The easiest way is to use Pre load asset manager. There is an example:
import gs.dataTransfer.PreloadAssetManager;
var preloader_obj = new PreloadAssetManager(["myFile1.swf","myFile2.swf"]);
this.onEnterFrame = function() {
myPreloader_mc.bar_mc._xscale = preloader_obj.percentLoaded_num;
if (preloader_obj.percentLoaded_num == 100) {
gotoAndPlay("start");
}
}
With percentLoaded_num you can set the amount that needs to be loaded before playing. Instead of the swf's use the flv's you want to preload. I haven't used it for flv's but it should work. Check the documentation for more information on this.
Also it's not a good idea to not allow buffering when not preloading the whole flv. Internet speeds are variable.
You can create custom buffering animations. If you don't want to show anything, I imagine you could create an animation that has nothing in it or that has no frames. See here for a video tutorial.
you can use flex to add the video you want and customize your own video controller
like this
Sample Player with and without Video Controller
Hope this gives you an idea.
Try this. Get the video duration and set that to your buffer time:
var netConn:NetConnection = new NetConnection();
// Create a local streaming connection
netConn.connect(null);
// Create a NetStream object and define an onStatus() function
var netStream:NetStream = new NetStream(netConn);
netStream.onStatus = function(infoObject) {
status_txt.text += "Status (NetStream)" + newline;
status_txt.text += "Level: "+infoObject.level + newline;
status_txt.text += "Code: "+infoObject.code + newline;
};
// Attach the NetStream video feed to the Video object
my_video.attachVideo(netStream);
my_video.onMetaData = function(videoMetaData:Object):Void {
var videoDuration = videoMetaData.duration;
}
// Set the buffer time
netStream.setBufferTime(videoDuration);
// Begin playing the FLV file
netStream.play("http://www.mydomain.com/myvid.flv");
精彩评论