Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

HLS Segment Edge Seeking #71

Merged
merged 11 commits into from
Feb 18, 2014
17 changes: 13 additions & 4 deletions src/VideoJS.as
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package{
import com.videojs.structs.ExternalEventName;
import com.videojs.structs.ExternalErrorEventName;
import com.videojs.Base64;

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
Expand Down Expand Up @@ -53,8 +53,8 @@ package{
_app.model.stageRect = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);

// add content-menu version info
var _ctxVersion:ContextMenuItem = new ContextMenuItem("VideoJS Flash Component v4.0.0", false, false);
var _ctxAbout:ContextMenuItem = new ContextMenuItem("Copyright © 2013 Brightcove, Inc.", false, false);
var _ctxVersion:ContextMenuItem = new ContextMenuItem("VideoJS Flash Component v4.0.9", false, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would there be any way we could load this version number in dynamically from the package.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to happen now, but that would be cool to set up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#75

var _ctxAbout:ContextMenuItem = new ContextMenuItem("Copyright © 2014 Brightcove, Inc.", false, false);
var _ctxMenu:ContextMenu = new ContextMenu();
_ctxMenu.hideBuiltInItems();
_ctxMenu.customItems.push(_ctxVersion, _ctxAbout);
Expand Down Expand Up @@ -187,6 +187,9 @@ package{
private function onGetPropertyCalled(pPropertyName:String = ""):*{

switch(pPropertyName){
case "lastSeekedTime":
return _app.model.lastSeekedTime;
break;
case "mode":
return _app.model.mode;
case "autoplay":
Expand Down Expand Up @@ -272,8 +275,14 @@ package{
return null;
}

private function onSetPropertyCalled(pPropertyName:String = "", pValue:* = null):void{
private function onSetPropertyCalled(pPropertyName:String = "", pValue:* = null):void{
switch(pPropertyName){
case "lastSeekedTime":
_app.model.lastSeekedTime = Number(pValue);
break;
case "duration":
_app.model.duration = Number(pValue);
break;
case "mode":
_app.model.mode = String(pValue);
break;
Expand Down
99 changes: 63 additions & 36 deletions src/com/videojs/VideoJSModel.as
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ package com.videojs{
import com.videojs.structs.ExternalEventName;
import com.videojs.structs.PlaybackType;
import com.videojs.structs.PlayerMode;

import flash.events.Event;
import flash.events.EventDispatcher;
import flash.external.ExternalInterface;
import flash.geom.Rectangle;
import flash.media.SoundMixer;
import flash.media.SoundTransform;
import flash.media.Video;
import flash.utils.ByteArray;
import flash.net.NetStreamAppendBytesAction;
import flash.utils.ByteArray;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indent is off on these

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.


public class VideoJSModel extends EventDispatcher{

Expand All @@ -43,9 +44,10 @@ package com.videojs{
private var _rtmpConnectionURL:String = "";
private var _rtmpStream:String = "";
private var _poster:String = "";

private var _lastSeekedTime:Number = 0;

private static var _instance:VideoJSModel;

public function VideoJSModel(pLock:SingletonLock){
if (!pLock is SingletonLock) {
throw new Error("Invalid Singleton access. Use VideoJSModel.getInstance()!");
Expand All @@ -64,11 +66,20 @@ package com.videojs{
}
return _instance;
}


public function get lastSeekedTime():Number {
return _lastSeekedTime;
}

public function set lastSeekedTime(value:Number):void {
_lastSeekedTime = value;
}

public function get mode():String{
return _mode;
}
public function set mode(pMode:String):void{

public function set mode(pMode:String):void {
switch(pMode){
case PlayerMode.VIDEO:
_mode = pMode;
Expand All @@ -84,32 +95,32 @@ package com.videojs{
public function get jsEventProxyName():String{
return _jsEventProxyName;
}
public function set jsEventProxyName(pName:String):void{
public function set jsEventProxyName(pName:String):void {
_jsEventProxyName = cleanEIString(pName);
}

public function get jsErrorEventProxyName():String{
return _jsErrorEventProxyName;
}
public function set jsErrorEventProxyName(pName:String):void{
public function set jsErrorEventProxyName(pName:String):void {
_jsErrorEventProxyName = cleanEIString(pName);
}

public function get stageRect():Rectangle{
return _stageRect;
}
public function set stageRect(pRect:Rectangle):void{
public function set stageRect(pRect:Rectangle):void {
_stageRect = pRect;
}

public function appendBuffer(bytes:ByteArray):void{
public function appendBuffer(bytes:ByteArray):void {
_provider.appendBuffer(bytes);
}

public function get backgroundColor():Number{
return _backgroundColor;
}
public function set backgroundColor(pColor:Number):void{
public function set backgroundColor(pColor:Number):void {
if(pColor < 0){
_backgroundColor = 0;
}
Expand All @@ -122,7 +133,7 @@ package com.videojs{
public function get backgroundAlpha():Number{
return _backgroundAlpha;
}
public function set backgroundAlpha(pAlpha:Number):void{
public function set backgroundAlpha(pAlpha:Number):void {
if(pAlpha < 0){
_backgroundAlpha = 0;
}
Expand All @@ -134,7 +145,7 @@ package com.videojs{
public function get videoReference():Video{
return _videoReference;
}
public function set videoReference(pVideo:Video):void{
public function set videoReference(pVideo:Video):void {
_videoReference = pVideo;
}

Expand All @@ -148,7 +159,7 @@ package com.videojs{
public function get volume():Number{
return _volume;
}
public function set volume(pVolume:Number):void{
public function set volume(pVolume:Number):void {
if(pVolume >= 0 && pVolume <= 1){
_volume = pVolume;
}
Expand All @@ -167,11 +178,17 @@ package com.videojs{
}
return 0;
}

public function set duration(value:Number):void {
if(_provider && _provider is HTTPVideoProvider) {
(_provider as HTTPVideoProvider).duration = value;
}
}

public function get autoplay():Boolean{
return _autoplay;
}
public function set autoplay(pValue:Boolean):void{
public function set autoplay(pValue:Boolean):void {
_autoplay = pValue;
}

Expand All @@ -181,7 +198,7 @@ package com.videojs{
}
return _src;
}
public function set src(pValue:String):void{
public function set src(pValue:String):void {
_src = pValue;
_rtmpConnectionURL = "";
_rtmpStream = "";
Expand All @@ -199,15 +216,15 @@ package com.videojs{
public function get rtmpConnectionURL():String{
return _rtmpConnectionURL;
}
public function set rtmpConnectionURL(pURL:String):void{
public function set rtmpConnectionURL(pURL:String):void {
_src = "";
_rtmpConnectionURL = pURL;
}

public function get rtmpStream():String{
return _rtmpStream;
}
public function set rtmpStream(pValue:String):void{
public function set rtmpStream(pValue:String):void {
_src = "";
_rtmpStream = pValue;
broadcastEventExternally(ExternalEventName.ON_SRC_CHANGE, _src);
Expand Down Expand Up @@ -235,7 +252,7 @@ package com.videojs{
* @param pValue
*
*/
public function set srcFromFlashvars(pValue:String):void{
public function set srcFromFlashvars(pValue:String):void {
_src = pValue;
_currentPlaybackType = PlaybackType.HTTP
initProvider();
Expand All @@ -251,7 +268,7 @@ package com.videojs{
public function get poster():String{
return _poster;
}
public function set poster(pValue:String):void{
public function set poster(pValue:String):void {
_poster = pValue;
broadcastEvent(new VideoJSEvent(VideoJSEvent.POSTER_SET));
}
Expand All @@ -270,15 +287,21 @@ package com.videojs{
*/
public function get time():Number{
if(_provider){
return _provider.time;
if(_provider is HTTPVideoProvider && _src == null)
{
//ExternalInterface.call('console.log', 'SWF Time', _lastSeekedTime, _provider.time);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this comment need to be left in? Also, would it be good to document what this function is doing now and why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment removed

return _lastSeekedTime + _provider.time;
} else {
return _provider.time;
}
}
return 0;
}

public function get muted():Boolean{
return (_volume == 0);
}
public function set muted(pValue:Boolean):void{
public function set muted(pValue:Boolean):void {
if(pValue){
var __lastSetVolume:Number = _lastSetVolume;
volume = 0;
Expand Down Expand Up @@ -314,20 +337,20 @@ package com.videojs{
public function get preload():Boolean{
return _preload;
}
public function set preload(pValue:Boolean):void{
public function set preload(pValue:Boolean):void {
_preload = pValue;
}

public function get loop():Boolean{
return _loop;
}
public function set loop(pValue:Boolean):void{
public function set loop(pValue:Boolean):void {
_loop = pValue;
}

public function get buffered():Number{
if(_provider){
return _provider.buffered;
return time + _provider.buffered;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a significant change. Are we sure this won't break the normal buffered operation, e.g. with plain mp4 playback?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will defer to @dmlap on this one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a bug but I believe it was fixed in a later commit. I would recommend waiting a little bit longer before pulling any of the HLS-related SWF changes into master. I'm still in the middle of testing everything.

}
return 0;
}
Expand Down Expand Up @@ -404,7 +427,7 @@ package com.videojs{
* @param e
*
*/
public function broadcastEvent(e:Event):void{
public function broadcastEvent(e:Event):void {
dispatchEvent(e);
}

Expand All @@ -413,7 +436,7 @@ package com.videojs{
* @param args
*
*/
public function broadcastEventExternally(... args):void{
public function broadcastEventExternally(... args):void {
if(_jsEventProxyName != ""){
if(ExternalInterface.available){
var __incomingArgs:* = args as Array;
Expand All @@ -428,7 +451,7 @@ package com.videojs{
* @param args
*
*/
public function broadcastErrorEventExternally(... args):void{
public function broadcastErrorEventExternally(... args):void {
if(_jsErrorEventProxyName != ""){
if(ExternalInterface.available){
var __incomingArgs:* = args as Array;
Expand All @@ -442,7 +465,7 @@ package com.videojs{
* Loads the video in a paused state.
*
*/
public function load():void{
public function load():void {
if(_provider){
_provider.load();
}
Expand All @@ -452,7 +475,7 @@ package com.videojs{
* Loads the video and begins playback immediately.
*
*/
public function play():void{
public function play():void {
if(_provider){
_provider.play();
}
Expand All @@ -462,7 +485,7 @@ package com.videojs{
* Pauses video playback.
*
*/
public function pause():void{
public function pause():void {
if(_provider){
_provider.pause();
}
Expand All @@ -472,7 +495,7 @@ package com.videojs{
* Resumes video playback.
*
*/
public function resume():void{
public function resume():void {
if(_provider){
_provider.resume();
}
Expand All @@ -483,7 +506,11 @@ package com.videojs{
* @param pValue
*
*/
public function seekBySeconds(pValue:Number):void{
public function seekBySeconds(pValue:Number):void {
ExternalInterface.call('console.log', 'SWF Received SeekValue', pValue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't leave console.log statements in the final version. At minimum it can throw an error in oldIE.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.


_lastSeekedTime = pValue;

if(_provider){
_provider.seekBySeconds(pValue);
}
Expand All @@ -494,7 +521,7 @@ package com.videojs{
* @param pValue A float from 0 to 1 that represents the desired seek percent.
*
*/
public function seekByPercent(pValue:Number):void{
public function seekByPercent(pValue:Number):void {
if(_provider){
_provider.seekByPercent(pValue);
}
Expand All @@ -504,7 +531,7 @@ package com.videojs{
* Stops video playback, clears the video element, and stops any loading proceeses.
*
*/
public function stop():void{
public function stop():void {
if(_provider){
_provider.stop();
}
Expand Down Expand Up @@ -539,7 +566,7 @@ package com.videojs{
return pString.replace(/[^A-Za-z0-9_.]/gi, "");
}

private function initProvider():void{
private function initProvider():void {
if(_provider){
_provider.die();
_provider = null;
Expand Down
Loading