NetStream Flash AS3 - 视频缩短,没有说明原因
我一天中大部分时间都在寻找这个答案,但发现的问题多于答案。
我有一个 .exe 全屏 Flash 应用程序,可以通过外部源加载视频文件(以及许多其他内容)。一切都正常,只是当视频播放时,它经常被切断并停止播放。停止播放的位置是随机的。有时不到 2 秒,有时会持续 30 秒,但从未制作过完整的 58 秒视频。
我已经跟踪了加载的字节总数,并且它们匹配(这是本地引用的文件,没有网络)。
这是代码。如果有更好的方法来做到这一点(不涉及课程),请帮忙。
function loadCaseVideo(sourceVideo:String):void {
//sourceVideo = reference link from XML data
if(!videoLoadedAlready){
var videoLoadedAlready:Boolean;
}
NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
var mNetConnection:NetConnection=new NetConnection();
mNetConnection.connect(null);
var mNetStream = new NetStream(mNetConnection);
var video = new Video();
video.width = 728;
video.height = 522;
video.y = 0;
video.x = 0;
video.attachNetStream(mNetStream);
videoHolder.videoInner.addChild(video);
mNetStream.client=new Object();
mNetStream.bufferTime=60;
mNetStream.play(sourceVideo);
mNetStream.addEventListener(NetStatusEvent.NET_STATUS, onNetStreamStatusEvent);
function onNetStreamStatusEvent(event:NetStatusEvent):void
{
trace(event.info.code);
if (event.info.code == "NetStream.Play.Start")
{
//trace("NetStream.Play.Start");
//trace(mNetStream.bytesLoaded +", " + mNetStream.bytesTotal);
}
if (event.info.code == "NetStream.Play.StreamNotFound")
{
//trace("Video Not Found");
}
if (event.info.code == "NetStream.Buffer.Flush")
{
//I saw this being called so I ran a trace on it, these two are equal, meaning fully loaded?
trace('loaded: '+ mNetStream.bytesLoaded +", total: " + mNetStream.bytesTotal);
}
}
function onMetaData(metadata:Object):void
{
}
}
I've searched most of the day for this answer, but found more questions than answers.
I have a .exe fullscreen flash app that loads video files (and many other things) through an external source. Everything links up okay, except that when the video plays, it often cuts out and just stops playing. Where it stops playing is random. Sometimes it's under 2 seconds, sometimes it will go for 30 seconds, but never has it made the full 58 seconds of the video.
I have traced the bytes loaded to the total and they match (it's a locally referenced file, no web).
Here's the code. If there's a better way to do this (that doesn't involve a class), please help.
function loadCaseVideo(sourceVideo:String):void {
//sourceVideo = reference link from XML data
if(!videoLoadedAlready){
var videoLoadedAlready:Boolean;
}
NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
var mNetConnection:NetConnection=new NetConnection();
mNetConnection.connect(null);
var mNetStream = new NetStream(mNetConnection);
var video = new Video();
video.width = 728;
video.height = 522;
video.y = 0;
video.x = 0;
video.attachNetStream(mNetStream);
videoHolder.videoInner.addChild(video);
mNetStream.client=new Object();
mNetStream.bufferTime=60;
mNetStream.play(sourceVideo);
mNetStream.addEventListener(NetStatusEvent.NET_STATUS, onNetStreamStatusEvent);
function onNetStreamStatusEvent(event:NetStatusEvent):void
{
trace(event.info.code);
if (event.info.code == "NetStream.Play.Start")
{
//trace("NetStream.Play.Start");
//trace(mNetStream.bytesLoaded +", " + mNetStream.bytesTotal);
}
if (event.info.code == "NetStream.Play.StreamNotFound")
{
//trace("Video Not Found");
}
if (event.info.code == "NetStream.Buffer.Flush")
{
//I saw this being called so I ran a trace on it, these two are equal, meaning fully loaded?
trace('loaded: '+ mNetStream.bytesLoaded +", total: " + mNetStream.bytesTotal);
}
}
function onMetaData(metadata:Object):void
{
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够通过以下方式解决此问题:
当时间线到达此帧时调用此函数:
当不处理流式网络时,这似乎是最好的方法做这个。我曾尝试首先使用这个组件,但当时我也在解决为什么 f4v 无法工作的问题 - 这是因为我使用的是旧版本的 Flash。当我使用 CS5 后,该组件就按照 f4v 的预期为我工作了。
I was able to resolve this by:
calling this function when the timeline reached this frame:
When NOT DEALING WITH STREAMING WEB, this seemed to be the best way to do this. I had tried to use this component first, but at that time I was also resolving why f4v wasn't working - which was because I was in an older version of Flash. Once I was using CS5, the component worked for me as expected with f4v's.