我们需要显示用户正在使用JW Player观看的视频的帧速率。我们已经尝试过使用JW Player 7 API尝试了所有内容,但它并没有为我们提供客户端帧速率。
我们已经构建了一个JW Player插件,该插件应该在视频播放时计算每个ENTER_FRAME事件的帧速率。
我们正在第61行收听ENTER_FRAME事件。 api.addEventListener(Event.ENTER_FRAME,calculateFPS);
每次输入新帧时,插件都会执行calculateFPS函数。帧速率显示在文本框中。
由于某种原因,计算的帧速率约为30 fps。这是不可能的,因为视频的原始帧速率是15 fps。 我认为问题可能出在第61行,其中eventlistener正在监听播放器而不是视频。是否可以将eventlistener直接链接到视频?
这是整个插件动作脚本代码。它基于JW Player插件示例APITester.as。
package {
import com.longtailvideo.jwplayer.events.*;
import com.longtailvideo.jwplayer.player.*;
import com.longtailvideo.jwplayer.plugins.*;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.events.Event;
import flash.utils.getTimer;
/** An example plugin that tests various player integrations. **/
public class APITester extends Sprite implements IPlugin6 {
[Embed(source="mute.png")]
private const MuteIcon:Class;
private var api:IPlayer;
private var field:TextField;
private var clickButton:Sprite;
public var startTime:Number;
public var framesNumber:Number = 0;
public var fps:TextField = new TextField();
/** Let the player know what the name of your plugin is. **/
public function get id():String {
return "apitester";
};
public function get target():String {
return "6.0";
}
/** Constructor **/
public function APITester() {
clickButton = new Sprite();
clickButton.addChild(new MuteIcon());
clickButton.y = 10;
clickButton.buttonMode = true;
addChild(clickButton);
startTime = getTimer();
addChild(fps);
};
/** Called by the player after the plugin has been created. **/
public function initPlugin(player:IPlayer, config:PluginConfig):void {
api = player;
api.addEventListener(Event.ENTER_FRAME, calculateFPS);
api.play();
};
private function calculateFPS(evt:Event):void {
var currentTime:Number = (getTimer() - startTime) / 1000;
framesNumber++;
if (currentTime > 1)
{
fps.text = "FPS: " + (Math.floor((framesNumber/currentTime)*10.0)/10.0);
startTime = getTimer();
framesNumber = 0;
}
};
/** If the player resizes itself, this gets called (including on setup). **/
public function resize(wid:Number, hei:Number):void {
clickButton.x = wid - 50;
}
}
}