AS3问题动态地将提示点添加到flv并寻找下一个提示点
我有一个flvplayback组件,我正在加载一个视频。
为了模仿下一帧和前一帧动作,我将为其长度的每一秒添加提示点。
下一帧/前一帧功能在视频上实现seekToNextNavCuePoint和
seekToPrevNavCuePoint
。
但它没有像我预期的那样工作。
这是实际的类文件。您可以使用包含库中按钮实例的fla文件直接编译它以进行播放暂停停止...此外,您还需要一些示例flv文件。
package
{
/*
The fla file contains buttons in the library;
*/
import flash.events.*;
import flash.display.*;
import fl.video.*;
public class testPlayer extends MovieClip
{
private var video1:FLVPlayback;
private var play_btn:PlayButton;
private var pause_btn:PauseButton;
private var stop_btn:StopButton;
private var nextFrame_btn:ForwardButton;
private var previousFrame_btn:ForwardButton;
public function testPlayer()
{
// constructor code
addEventListener(Event.ADDED_TO_STAGE,onAdded);
}
private function onAdded(event:Event)
{
setPlayer();
setPath();
setButtons();
}
private function setPlayer()
{
video1 = new FLVPlayback ;
this.addChild(video1);
video1.x = 50;
video1.y = 50;
}
private function setPath()
{
video1.addEventListener(VideoEvent.READY, flvPlayback_ready);
video1.addEventListener(MetadataEvent.CUE_POINT, flvPlayback_cuePoint);
// here you can give any flv you have and its total time
video1.load("test.flv",3600,false);
}
private function flvPlayback_ready(evt:VideoEvent):void
{
var num:Number = video1.totalTime;
for (var i:int=0; i<num; i++)
{
video1.addASCuePoint(i, "cuePoint"+String(i));
}
this.removeEventListener(VideoEvent.READY, flvPlayback_ready);
}
private function flvPlayback_cuePoint(evt:MetadataEvent):void
{
trace("CUE POINT!!!");
trace("t", "name:", evt.info.name);// name: cuePoint1
trace("t", "time:", evt.info.time);// time: 1
trace("t", "type:", evt.info.type);// type: actionscript
}
private function setButtons()
{
play_btn=new PlayButton();
pause_btn=new PauseButton();
stop_btn=new StopButton();
nextFrame_btn=new ForwardButton();
previousFrame_btn=new ForwardButton();
play_btn.addEventListener(MouseEvent.CLICK,onPlay);
pause_btn.addEventListener(MouseEvent.CLICK,onPause);
stop_btn.addEventListener(MouseEvent.CLICK,onStop);
nextFrame_btn.addEventListener(MouseEvent.CLICK,onNextFrame);
previousFrame_btn.addEventListener(MouseEvent.CLICK,onPreviousFrame);
play_btn.x = 50;
play_btn.y = 350;
previousFrame_btn.x = 125;
previousFrame_btn.y = 350;
previousFrame_btn.scaleX *= -1;
nextFrame_btn.x = 150;
nextFrame_btn.y = 350;
pause_btn.x = 200;
pause_btn.y = 350;
stop_btn.x = 250;
stop_btn.y = 350;
addChild(play_btn);
addChild(pause_btn);
addChild(stop_btn);
addChild(previousFrame_btn);
addChild(nextFrame_btn);
}
private function onPlay(event:MouseEvent)
{
video1.play();
}
private function onPause(event:MouseEvent)
{
video1.pause();
}
private function onStop(event:MouseEvent)
{
video1.stop();
}
private function onNextFrame(event:Event)
{
if (video1.playing)
{
//video1.pause();
}
// this is not working the way i expected it to
video1.seekToNextNavCuePoint();
}
private function onPreviousFrame(event:Event)
{
if (video1.playing)
{
//video1.pause();
}
// this is not working the way i expected it to
video1.seekToPrevNavCuePoint();
}
}
}
我在这里错过了什么?只是在不调用next / prev帧功能的情况下运行它会显示根据flvPlayback_cuePoint函数每秒激活提示点。
update:
当我单击previousFrame按钮时,无论当前提示点在何处,帧都会转移到cuepoint1。当我单击nextFrame按钮时,提示点和显示似乎会更改为下一个,但在几次单击后,提示点将立即变为1,视频将从头开始。
问题1:使用addASCuePoint()沿着加载的电影的长度在ActionScript 3.0中动态添加提示点的正确方法是什么?
问题2:我们能否以33ms的间隔添加提示点,我们可以在此处添加提示点
可以正确寻求?
问题3:上面的代码有什么问题?
更新:
添加赏金:解决问题并回答3个问题
更新:
用上述方法进行了多次不成功的试验并尝试了Trevor的建议。
我通过seek()方法获得了功能,但缺乏精确性。
package
{
/*
The fla file contains buttons in the library;
*/
import flash.events.*;
import flash.display.*;
import fl.video.*;
public class testPlayer extends MovieClip
{
private var video1:FLVPlayback;
private var play_btn:PlayButton;
private var pause_btn:PauseButton;
private var stop_btn:StopButton;
private var nextFrame_btn:ForwardButton;
private var previousFrame_btn:ForwardButton;
private var playHeadTime:Number;
private var cue:Object;
public function testPlayer()
{
addEventListener(Event.ADDED_TO_STAGE,onAdded);
}
private function onAdded(event:Event)
{
setPlayer();
setPath();
setButtons();
playHeadTime = 0;
}
private function setPlayer()
{
video1 = new FLVPlayback ;
this.addChild(video1);
video1.x = 50;
video1.y = 50;
}
private function setPath()
{
video1.playheadUpdateInterval = 50;
video1.seekToPrevOffset = 0.01;
video1.addEventListener(VideoEvent.READY, flvPlayback_ready);
video1.addEventListener(MetadataEvent.CUE_POINT, flvPlayback_cuePoint);
video1.load("test.flv",3600,false);
}
private function flvPlayback_ready(evt:VideoEvent):void
{
// changing this loop to add more cue points causes the program to hang.
for (var i:int=0; i<video1.totalTime; i++)
{
cue= new Object();
cue.time = i;
cue.type = "navigation";// this does not seem to get set the type
cue.name = "cuePoint" + String(i);
video1.addASCuePoint(cue,cue.name);
}
video1.removeEventListener(VideoEvent.READY, flvPlayback_ready);
}
private function flvPlayback_cuePoint(evt:MetadataEvent):void
{
trace("CUE POINT!!!");
trace("t", "name:", evt.info.name);// name: cuePoint1
trace("t", "time:", evt.info.time ," playhead time :",String(Math.round(video1.playheadTime)));// time: 1
trace("t", "====type:", evt.info.type);// traces actionscript instead of navigation
}
private function setButtons()
{
play_btn=new PlayButton();
pause_btn=new PauseButton();
stop_btn=new StopButton();
nextFrame_btn=new ForwardButton();
previousFrame_btn=new ForwardButton();
play_btn.addEventListener(MouseEvent.CLICK,onPlay);
pause_btn.addEventListener(MouseEvent.CLICK,onPause);
stop_btn.addEventListener(MouseEvent.CLICK,onStop);
nextFrame_btn.addEventListener(MouseEvent.CLICK,onNextFrame);
previousFrame_btn.addEventListener(MouseEvent.CLICK,onPreviousFrame);
play_btn.x = 50;
play_btn.y = 350;
previousFrame_btn.x = 125;
previousFrame_btn.y = 350;
previousFrame_btn.scaleX *= -1;
nextFrame_btn.x = 150;
nextFrame_btn.y = 350;
pause_btn.x = 200;
pause_btn.y = 350;
stop_btn.x = 250;
stop_btn.y = 350;
addChild(play_btn);
addChild(pause_btn);
addChild(stop_btn);
addChild(previousFrame_btn);
addChild(nextFrame_btn);
}
private function onPlay(event:MouseEvent)
{
video1.play();
}
private function onPause(event:MouseEvent)
{
video1.pause();
}
private function onStop(event:MouseEvent)
{
video1.stop();
}
private function onNextFrame(event:Event)
{
if (video1.playing)
{
video1.stop();
}
trace("Calling nextFrame :::",playHeadTime);
video1.seek(playHeadTime);
playHeadTime += 1;
}
private function onPreviousFrame(event:Event)
{
if (video1.playing)
{
video1.stop();
}
trace("Calling prevFrame ::::",playHeadTime);
video1.seek(playHeadTime);
playHeadTime -= 1;
}
}
}
下面的输出如下所示。问题是下一个和以前的功能一直在跳过提示点,似乎不适用于某些提示点。下面的曲线应该给出清晰的图像。
Calling nextFrame ::: 0
CUE POINT!!!
name: cuePoint0
time: 0 playhead time : 0
====type: actionscript
Calling nextFrame ::: 1
CUE POINT!!!
name: cuePoint2
time: 2 playhead time : 2
====type: actionscript
Calling nextFrame ::: 2
Calling nextFrame ::: 3
CUE POINT!!!
name: cuePoint4
time: 4 playhead time : 4
====type: actionscript
Calling prevFrame :::: 4
Calling prevFrame :::: 3
Calling prevFrame :::: 2
CUE POINT!!!
name: cuePoint2
time: 2 playhead time : 2
====type: actionscript
编辑:
问题1:我们如何在连续的提示点上触发MetadataEvent.CUE_POINT,即不跳过提示点。
问题2:如何在每个提示点触发MetadataEvent.CUE_POINT事件时,如果它们以100毫秒的间隔发出。
没有找到相关结果
已邀请:
3 个回复
念炯
芦歉竭皑
会正常工作,我唯一关心的是i的初始值是0,我不确定这个值是否会被存储或触发......但它可能是。 Q2。是的,如果视频是流式传输的,或者它是渐进式的,并且那里有一个关键帧,帧速率为30fps或更高。为了每33毫秒获得一次提示点,您的视频需要为30fps。如果你可以每40毫秒使用一次提示点,那么25fps就可以了。帧速率在编码时设置,通常只是与源相同。 Q3。一些事情要尝试: 尝试将
设置为较低的值,例如。 0.1(或者如果你打算在帧上放置提示点,那么会小很多),默认设置为1,这意味着它可能会跳过提示点。 同时尝试将
从250降低到50,这可能有助于寻求。如果频繁寻求每30ms,你将不得不降低它。 如果视频是渐进式的,请不要进一步搜索已加载的视频,否则播放头将跳回到开头。 不允许用户单击下一个,直到上一个搜索命令完成,因为
基于当前播放头时间。或者,您可以将值传递给
,以便用户可以多次按下一次,而无需等待搜索命令完成。 如果你想要更好的控制,你可以跟踪你在视频中的位置,然后使用
创建自己的
和
功能。例如。
舞备联
问题2:我们能否以33毫秒的间隔添加提示点,我们可以正确地寻求? 请参阅问题1的答案,确保不要超过flv的长度如果您在33ms更换视觉项目,您将使人眼睛流血 问题3:上面的代码有什么问题? 您从未定义过提示点的位置和内容。你能举个例子说明你会在每个提示点做什么吗? 当你提供更多信息时,我会编辑这个。