[Pkg-javascript-commits] [jarisplayer] 13/80: rtmp, youtube and pseudo streaming support as many more improvements
Jonas Smedegaard
dr at jones.dk
Tue May 10 08:45:31 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository jarisplayer.
commit 96179d72d99483877151b4bc00e70b007b22ae8a
Author: jgmylm <jgmylm at edf201c3-a14d-0410-a11e-aa85364efa9f>
Date: Thu Mar 11 08:05:24 2010 +0000
rtmp, youtube and pseudo streaming support as many more improvements
git-svn-id: https://jaris.svn.sourceforge.net/svnroot/jaris/trunk@13 edf201c3-a14d-0410-a11e-aa85364efa9f
---
bin/JarisFLVPlayer.swf | Bin 18867 -> 20137 bytes
bin/index.html | 6 +-
changes.txt | 10 +-
documentation.txt | 13 +-
src/jaris/Main.hx | 11 +-
src/jaris/events/PlayerEvents.hx | 2 +-
src/jaris/player/Player.hx | 446 ++++++++++++++++++++++++++++------
src/jaris/player/StreamType.hx | 1 +
src/jaris/player/controls/Controls.hx | 81 +++---
src/jaris/utils/Utils.hx | 27 ++
10 files changed, 467 insertions(+), 130 deletions(-)
diff --git a/bin/JarisFLVPlayer.swf b/bin/JarisFLVPlayer.swf
index f3090b3..96191fa 100644
Binary files a/bin/JarisFLVPlayer.swf and b/bin/JarisFLVPlayer.swf differ
diff --git a/bin/index.html b/bin/index.html
index c5f0e87..e692610 100644
--- a/bin/index.html
+++ b/bin/index.html
@@ -10,9 +10,10 @@
<script src="js/swfobject.js" type="text/javascript"></script>
<script type="text/javascript">
var flashvarsVideo = {
- file: "http://jaris.sourceforge.net/files/jaris-intro.flv",
+ source: "http://jaris.sourceforge.net/files/jaris-intro.flv",
type: "video",
streamtype: "file",
+ server: "",//Used for rtmp streams
duration: "52",
poster: "http://jaris.sourceforge.net/images/poster.png",
autostart: "false",
@@ -28,9 +29,10 @@
hovercolor: "67A8C1"
};
var flashvarsAudio = {
- file: "http://jaris.sourceforge.net/files/audio.mp3",
+ source: "http://jaris.sourceforge.net/files/audio.mp3",
type: "audio",
streamtype: "file",
+ server: "",//Used for rtmp streams
duration: "00:04:25",
poster: "http://jaris.sourceforge.net/images/poster.png",
autostart: "false",
diff --git a/changes.txt b/changes.txt
index 12178ad..55024a6 100644
--- a/changes.txt
+++ b/changes.txt
@@ -1,4 +1,12 @@
-Jaris FLV Player v2.0.2 beta - 03/09/2010
+Jaris FLV Player v2.0.3 beta - 03/10/2010
+
+ * Support for rtmp streaming
+ * support for youtube
+ * better support for http streaming like lighttpd
+ * Fixed calculation of width on original aspect ratio larger than stage
+ * And many hours of improvements
+
+Jaris FLV Player v2.0.2 beta - 03/09/2010
* Implement EventDispatcher on Player class instead of using custom event mechanism
* Fixed not getting initial stage widht and height on IE when using swfobjects
diff --git a/documentation.txt b/documentation.txt
index d65fe56..8232318 100644
--- a/documentation.txt
+++ b/documentation.txt
@@ -17,7 +17,7 @@ The above example is one of the ways to embed the player to your html files. Jus
<param name="quality" value="high">
<param name="scale" value="noscale">
<param name="wmode" value="opaque">
- <param name="flashvars" value="file=jaris-intro.mp4&type=video&streamtype=file&poster=poster.png&autostart=false&logo=logo.png&logoposition=top left&logoalpha=30&logowidth=130&logolink=http://jaris.sourceforge.net&hardwarescaling=false&darkcolor=000000&brightcolor=4c4c4c&controlcolor=FFFFFF&hovercolor=67A8C1">
+ <param name="flashvars" value="source=jaris-intro.mp4&type=video&streamtype=file&poster=poster.png&autostart=false&logo=logo.png&logoposition=top left&logoalpha=30&logowidth=130&logolink=http://jaris.sourceforge.net&hardwarescaling=false&darkcolor=000000&brightcolor=4c4c4c&controlcolor=FFFFFF&hovercolor=67A8C1">
<param name="seamlesstabbing" value="false">
<embed
type="application/x-shockwave-flash"
@@ -30,7 +30,7 @@ The above example is one of the ways to embed the player to your html files. Jus
quality="high"
scale="noscale"
wmode="opaque"
- flashvars="file=jaris-intro.mp4&type=video&streamtype=file&poster=poster.png&autostart=false&logo=logo.png&logoposition=top left&logoalpha=30&logowidth=130&logolink=http://jaris.sourceforge.net&hardwarescaling=false&darkcolor=000000&brightcolor=4c4c4c&controlcolor=FFFFFF&hovercolor=67A8C1"
+ flashvars="source=jaris-intro.mp4&type=video&streamtype=file&poster=poster.png&autostart=false&logo=logo.png&logoposition=top left&logoalpha=30&logowidth=130&logolink=http://jaris.sourceforge.net&hardwarescaling=false&darkcolor=000000&brightcolor=4c4c4c&controlcolor=FFFFFF&hovercolor=67A8C1"
seamlesstabbing="false"
>
<noembed>
@@ -45,14 +45,17 @@ Flash Variables
Here is the list of variables that you can pass to the player.
- * file:
- This is the actual file that is going to be played.
+ * source:
+ This is the actual path of the media that is going to be played.
* type:
The type of file to play, allowable values are: audio, video.
* streamtype:
- The stream type of the file, allowable values are: file, http (for pseudostream) and soon rmtp.
+ The stream type of the file, allowable values are: file, http, rmtp, youtube.
+
+ * server:
+ Used in coordination with rtmp stream servers
* duration:
Total times in seconds for input media or formatted string in the format hh:mm:ss
diff --git a/src/jaris/Main.hx b/src/jaris/Main.hx
index f7268a3..4cdee91 100644
--- a/src/jaris/Main.hx
+++ b/src/jaris/Main.hx
@@ -27,7 +27,6 @@ import flash.display.MovieClip;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
-import flash.events.Event;
import flash.Lib;
import flash.system.Capabilities;
import jaris.display.Logo;
@@ -70,17 +69,19 @@ class Main
var autoStart:Bool = parameters.autostart == "true" || parameters.autostart == "" || parameters.autostart == null? true: false;
var type:String = parameters.type != "" && parameters.type != null? parameters.type : InputType.VIDEO;
var streamType:String = parameters.streamtype != "" && parameters.streamtype != null? parameters.streamtype : StreamType.FILE;
+ var server:String = parameters.server != "" && parameters.server != null? parameters.server : "";
player.setType(type);
player.setStreamType(streamType);
+ player.setServer(server);
if (autoStart)
{
- player.load(parameters.file, type, streamType);
+ player.load(parameters.source, type, streamType, server);
}
else
{
- player.setSource(parameters.file);
+ player.setSource(parameters.source);
}
player.setPoster(posterImage);
@@ -89,8 +90,8 @@ class Main
else
{
//For development purposes
- //player.load("http://jaris.sourceforge.net/files/jaris-intro.flv", InputType.VIDEO, StreamType.FILE);
- player.load("http://jaris.sourceforge.net/files/audio.mp3", InputType.AUDIO, StreamType.FILE);
+ player.load("http://jaris.sourceforge.net/files/jaris-intro.flv", InputType.VIDEO, StreamType.FILE);
+ //player.load("http://jaris.sourceforge.net/files/audio.mp3", InputType.AUDIO, StreamType.FILE);
}
//Modify Context Menu
diff --git a/src/jaris/events/PlayerEvents.hx b/src/jaris/events/PlayerEvents.hx
index 9211fd3..4e71e75 100644
--- a/src/jaris/events/PlayerEvents.hx
+++ b/src/jaris/events/PlayerEvents.hx
@@ -28,7 +28,7 @@ import flash.media.Sound;
import flash.net.NetStream;
/**
- * Implements a player events
+ * Implements the player events
*/
class PlayerEvents extends Event
{
diff --git a/src/jaris/player/Player.hx b/src/jaris/player/Player.hx
index 398e1b3..a057f37 100644
--- a/src/jaris/player/Player.hx
+++ b/src/jaris/player/Player.hx
@@ -22,10 +22,12 @@
package jaris.player;
+import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageDisplayState;
+import flash.events.AsyncErrorEvent;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.FullScreenEvent;
@@ -46,11 +48,13 @@ import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.URLRequest;
import flash.system.Capabilities;
+import flash.system.Security;
import flash.ui.Keyboard;
import flash.ui.Mouse;
import flash.utils.Timer;
import jaris.display.Poster;
import jaris.events.PlayerEvents;
+import jaris.utils.Utils;
/**
* Jaris main video player
@@ -93,6 +97,7 @@ class Player extends EventDispatcher
private var _stopped:Bool;
private var _useHardWareScaling:Bool;
private var _poster:Poster;
+ private var _youtubeLoader:Loader;
//}
@@ -132,13 +137,13 @@ class Player extends EventDispatcher
//}
- //{Initialize video and connection objets
+ //{Initialize video and connection objects
_connection = new NetConnection();
+ _connection.client = this;
_connection.connect(null);
_stream = new NetStream(_connection);
_video = new Video(_stage.stageWidth, _stage.stageHeight);
- _video.attachNetStream(_stream);
_movieClip.addChild(_video);
//}
@@ -157,7 +162,8 @@ class Player extends EventDispatcher
_stage.addEventListener(Event.RESIZE, onResize);
_hideMouseTimer.addEventListener(TimerEvent.TIMER, hideMouseTimer);
_checkAudioTimer.addEventListener(TimerEvent.TIMER, checkAudioTimer);
- _stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
+ _connection.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
+ _connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
//}
}
//}
@@ -205,6 +211,24 @@ class Player extends EventDispatcher
//{Events
/**
+ * Callback after bandwidth calculation for rtmp streams
+ */
+ private function onBWDone():Void
+ {
+ //Need to study this more
+ }
+
+ /**
+ * Triggers error event on rtmp connections
+ * @param event
+ */
+ private function onAsyncError(event:AsyncErrorEvent):Void
+ {
+ //TODO: Should trigger event for controls to display error message
+ trace(event.error);
+ }
+
+ /**
* Checks if connection failed or succeed
* @param event
*/
@@ -213,28 +237,46 @@ class Player extends EventDispatcher
switch (event.info.code)
{
case "NetConnection.Connect.Success":
+ if (_streamType == StreamType.RTMP)
+ {
+ _stream = new NetStream(_connection);
+ _stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
+ _stream.bufferTime = 10;
+ _stream.play(Utils.rtmpSourceParser(_mediaSource), true);
+ _stream.client = this;
+ _video.attachNetStream(_stream);
+ }
callEvents(PlayerEvents.CONNECTION_SUCCESS);
case "NetStream.Play.StreamNotFound":
- trace("Stream not found: " + _mediaSource);
+ trace("Stream not found: " + _mediaSource); //Replace with a dispatch for error event
callEvents(PlayerEvents.CONNECTION_FAILED);
case "NetStream.Play.Stop":
- if (_isPlaying) { _stream.togglePause(); }
- _isPlaying = false;
- _mediaEndReached = true;
- callEvents(PlayerEvents.PLAYBACK_FINISHED);
+ if (_streamType != StreamType.RTMP)
+ {
+ if (_isPlaying) { _stream.togglePause(); }
+ _isPlaying = false;
+ _mediaEndReached = true;
+ callEvents(PlayerEvents.PLAYBACK_FINISHED);
+ }
case "NetStream.Play.Start":
_isPlaying = true;
_mediaEndReached = false;
- if (_stream.bytesLoaded != _stream.bytesTotal)
+ if (_stream.bytesLoaded != _stream.bytesTotal || _streamType == StreamType.RTMP)
{
callEvents(PlayerEvents.BUFFERING);
}
case "NetStream.Seek.Notify":
_mediaEndReached = false;
+ if (_streamType == StreamType.RTMP)
+ {
+ _isPlaying = true;
+ callEvents(PlayerEvents.PLAY_PAUSE);
+ callEvents(PlayerEvents.BUFFERING);
+ }
case "NetStream.Buffer.Empty":
if (_stream.bytesLoaded != _stream.bytesTotal)
@@ -432,7 +474,17 @@ class Player extends EventDispatcher
*/
private function onLastSecond(data:Dynamic):Void
{
- //To work on it?
+ trace("last second pseudostream");
+ }
+
+ /**
+ * Triggers when playbacks end on rtmp streaming server
+ */
+ private function onPlayStatus(info:Dynamic):Void
+ {
+ _isPlaying = false;
+ _mediaEndReached = true;
+ callEvents(PlayerEvents.PLAYBACK_FINISHED);
}
/**
@@ -508,6 +560,120 @@ class Player extends EventDispatcher
_mediaDuration = ((_sound.bytesTotal / _sound.bytesLoaded) * _sound.length) / 1000;
callEvents(PlayerEvents.MEDIA_INITIALIZED);
}
+
+ /**
+ * Initializes the youtube loader object
+ * @param event
+ */
+ private function onYouTubeLoaderInit(event:Event):Void
+ {
+ _youtubeLoader.content.addEventListener("onReady", onYoutubeReady);
+ _youtubeLoader.content.addEventListener("onError", onYoutubeError);
+ _youtubeLoader.content.addEventListener("onStateChange", onYoutubeStateChange);
+ _youtubeLoader.content.addEventListener("onPlaybackQualityChange", onYoutubePlaybackQualityChange);
+
+ }
+
+ /**
+ * This event is fired when the player is loaded and initialized, meaning it is ready to receive API calls.
+ */
+ private function onYoutubeReady(event:Event):Void
+ {
+ _movieClip.addChild(_youtubeLoader.content);
+ _movieClip.setChildIndex(_youtubeLoader.content, 0);
+ Reflect.field(_youtubeLoader.content, "setSize")(_stage.stageWidth, _stage.stageHeight);
+ Reflect.field(_youtubeLoader.content, "loadVideoByUrl")(Utils.youtubeSourceParse(_mediaSource));
+ callEvents(PlayerEvents.BUFFERING);
+ }
+
+ /**
+ * This event is fired whenever the player's state changes. Possible values are unstarted (-1), ended (0),
+ * playing (1), paused (2), buffering (3), video cued (5). When the SWF is first loaded it will broadcast
+ * an unstarted (-1) event. When the video is cued and ready to play it will broadcast a video cued event (5).
+ * @param event
+ */
+ private function onYoutubeStateChange(event:Event):Void
+ {
+ var status:UInt = Std.parseInt(Reflect.field(event, "data"));
+
+ switch(status)
+ {
+ case -1:
+ callEvents(PlayerEvents.BUFFERING);
+
+ case 0:
+ _isPlaying = false;
+ _mediaEndReached = true;
+ callEvents(PlayerEvents.PLAYBACK_FINISHED);
+
+ case 1:
+ if (_firstLoad)
+ {
+ _isPlaying = true;
+
+ _videoWidth = _stage.stageWidth;
+ _videoHeight = _stage.stageHeight;
+
+ _firstLoad = false;
+
+ if (_poster != null)
+ {
+ _poster.visible = false;
+ }
+
+ _mediaLoaded = true;
+ _mediaDuration = Reflect.field(_youtubeLoader.content, "getDuration")();
+ trace(_mediaDuration);
+ _aspectRatio = AspectRatio.getAspectRatio(_videoWidth, _videoHeight);
+ _originalAspectRatio = _aspectRatio;
+
+ callEvents(PlayerEvents.CONNECTION_SUCCESS);
+ callEvents(PlayerEvents.MEDIA_INITIALIZED);
+
+ resizeAndCenterPlayer();
+ }
+ callEvents(PlayerEvents.NOT_BUFFERING);
+
+ case 2:
+ callEvents(PlayerEvents.NOT_BUFFERING);
+
+ case 3:
+ callEvents(PlayerEvents.BUFFERING);
+
+ case 5:
+ callEvents(PlayerEvents.NOT_BUFFERING);
+ }
+ }
+
+ /**
+ * This event is fired whenever the video playback quality changes. For example, if you call the
+ * setPlaybackQuality(suggestedQuality) function, this event will fire if the playback quality actually
+ * changes. Your code should respond to the event and should not assume that the quality will automatically
+ * change when the setPlaybackQuality(suggestedQuality) function is called. Similarly, your code should not
+ * assume that playback quality will only change as a result of an explicit call to setPlaybackQuality or any
+ * other function that allows you to set a suggested playback quality.
+ *
+ * The value that the event broadcasts is the new playback quality. Possible values are "small", "medium",
+ * "large" and "hd720".
+ * @param event
+ */
+ private function onYoutubePlaybackQualityChange(event:Event):Void
+ {
+ trace(Reflect.field(event, "data"));
+ }
+
+ /**
+ * This event is fired when an error in the player occurs. The possible error codes are 100, 101,
+ * and 150. The 100 error code is broadcast when the video requested is not found. This occurs when
+ * a video has been removed (for any reason), or it has been marked as private. The 101 error code is
+ * broadcast when the video requested does not allow playback in the embedded players. The error code
+ * 150 is the same as 101, it's just 101 in disguise!
+ * @param event
+ */
+ private function onYoutubeError(event:Event):Void
+ {
+ trace(Reflect.field(event, "data"));
+ }
//}
@@ -540,16 +706,39 @@ class Player extends EventDispatcher
*/
private function resizeAndCenterPlayer():Void
{
- _video.height = _stage.stageHeight;
- _video.width = _video.height * _aspectRatio;
-
- _video.x = (_stage.stageWidth / 2) - (_video.width / 2);
-
- _videoMask.graphics.clear();
- _videoMask.graphics.lineStyle();
- _videoMask.graphics.beginFill(0x000000, 0);
- _videoMask.graphics.drawRect(_video.x, _video.y, _video.width, _video.height);
- _videoMask.graphics.endFill();
+ if (_streamType != StreamType.YOUTUBE)
+ {
+ _video.height = _stage.stageHeight;
+ _video.width = _video.height * _aspectRatio;
+
+ _video.x = (_stage.stageWidth / 2) - (_video.width / 2);
+ _video.y = 0;
+
+ if (_video.width > _stage.stageWidth && _aspectRatio == _originalAspectRatio)
+ {
+ var aspectRatio:Float = _videoHeight / _videoWidth;
+ _video.width = _stage.stageWidth;
+ _video.height = aspectRatio * _video.width;
+ _video.x = 0;
+ _video.y = (_stage.stageHeight / 2) - (_video.height / 2);
+ }
+
+ _videoMask.graphics.clear();
+ _videoMask.graphics.lineStyle();
+ _videoMask.graphics.beginFill(0x000000, 0);
+ _videoMask.graphics.drawRect(_video.x, _video.y, _video.width, _video.height);
+ _videoMask.graphics.endFill();
+ }
+ else
+ {
+ Reflect.field(_youtubeLoader.content, "setSize")(_stage.stageWidth, _stage.stageHeight);
+
+ _videoMask.graphics.clear();
+ _videoMask.graphics.lineStyle();
+ _videoMask.graphics.beginFill(0x000000, 0);
+ _videoMask.graphics.drawRect(0, 0, _stage.stageWidth, _stage.stageHeight);
+ _videoMask.graphics.endFill();
+ }
callEvents(PlayerEvents.RESIZE);
}
@@ -623,6 +812,8 @@ class Player extends EventDispatcher
*/
public function load(source:String, type:String="video", streamType:String="file", server:String=""):Void
{
+ stopAndClose();
+
_type = type;
_streamType = streamType;
_mediaSource = source;
@@ -636,11 +827,30 @@ class Player extends EventDispatcher
callEvents(PlayerEvents.BUFFERING);
- if (_type == InputType.VIDEO)
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ Security.allowDomain("www.youtube.com");
+ _youtubeLoader = new Loader();
+ _youtubeLoader.contentLoaderInfo.addEventListener(Event.INIT, onYouTubeLoaderInit);
+ _youtubeLoader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
+ }
+ else if (_type == InputType.VIDEO && (_streamType == StreamType.FILE || _streamType == StreamType.PSEUDOSTREAM))
{
+ _connection.connect(null);
+ _stream = new NetStream(_connection);
+ _stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
_stream.bufferTime = 10;
_stream.play(source);
_stream.client = this;
+ _video.attachNetStream(_stream);
+ }
+ else if (_type == InputType.VIDEO && _streamType == StreamType.RTMP)
+ {
+ _connection.connect(_server);
+ }
+ else if (_type == InputType.AUDIO && _streamType == StreamType.RTMP)
+ {
+ _connection.connect(_server);
}
else if(_type == InputType.AUDIO && _streamType == StreamType.FILE)
{
@@ -653,20 +863,27 @@ class Player extends EventDispatcher
*/
public function stopAndClose():Void
{
- _mediaLoaded = false;
- _isPlaying = false;
- _stopped = true;
- _startTime = 0;
- _poster.visible = true;
-
- if (_type == InputType.VIDEO)
- {
- _stream.close();
- }
- else
+ if (_mediaLoaded)
{
- _soundChannel.stop();
- _sound.close();
+ _mediaLoaded = false;
+ _isPlaying = false;
+ _stopped = true;
+ _startTime = 0;
+ _poster.visible = true;
+
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ Reflect.field(_youtubeLoader.content, "destroy")();
+ }
+ else if (_type == InputType.VIDEO)
+ {
+ _stream.close();
+ }
+ else
+ {
+ _soundChannel.stop();
+ _sound.close();
+ }
}
}
@@ -676,7 +893,7 @@ class Player extends EventDispatcher
*/
public function forward():Float
{
- var seekTime = (getTime() + 8) + _startTime;
+ var seekTime = (getCurrentTime() + 8) + _startTime;
if (getDuration() > seekTime)
{
@@ -692,7 +909,7 @@ class Player extends EventDispatcher
*/
public function rewind():Float
{
- var seekTime = (getTime() - 8) + _startTime;
+ var seekTime = (getCurrentTime() - 8) + _startTime;
if (seekTime >= _startTime)
{
@@ -711,7 +928,7 @@ class Player extends EventDispatcher
{
if (_startTime <= 1 && _downloadCompleted)
{
- if (_type == InputType.VIDEO)
+ if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
{
_stream.seek(seekTime);
}
@@ -727,7 +944,7 @@ class Player extends EventDispatcher
}
else if(_seekPoints.length > 0 && _streamType == StreamType.PSEUDOSTREAM)
{
- seekTime = getBestSeekPoint(seekTime);
+ //seekTime = getBestSeekPoint(seekTime);
if (canSeek(seekTime))
{
@@ -735,6 +952,8 @@ class Player extends EventDispatcher
}
else if(seekTime != _startTime)
{
+ _startTime = seekTime;
+
var url:String;
if (_mediaSource.indexOf("?") != -1)
{
@@ -744,14 +963,29 @@ class Player extends EventDispatcher
{
url = _mediaSource + "?start=" + seekTime;
}
-
- _startTime = seekTime;
_stream.play(url);
}
}
+ else if (_streamType == StreamType.YOUTUBE)
+ {
+ if (!canSeek(seekTime))
+ {
+ _startTime = seekTime;
+ Reflect.field(_youtubeLoader.content, "seekTo")(seekTime);
+ }
+ else
+ {
+ Reflect.field(_youtubeLoader.content, "seekTo")(seekTime);
+ }
+
+ }
+ else if (_streamType == StreamType.RTMP)
+ {
+ _stream.seek(seekTime);
+ }
else if(canSeek(seekTime))
{
- if (_type == InputType.VIDEO)
+ if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
{
seekTime = getBestSeekPoint(seekTime);
_stream.seek(seekTime);
@@ -833,8 +1067,14 @@ class Player extends EventDispatcher
if (_mediaEndReached)
{
_mediaEndReached = false;
+ _startTime = 0;
- if (_type == InputType.VIDEO)
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ Reflect.field(_youtubeLoader.content, "seekTo")(0);
+ Reflect.field(_youtubeLoader.content, "playVideo")();
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
{
_stream.seek(0);
_stream.togglePause();
@@ -847,7 +1087,18 @@ class Player extends EventDispatcher
}
else if (_mediaLoaded)
{
- if (_type == InputType.VIDEO)
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ if (_isPlaying)
+ {
+ Reflect.field(_youtubeLoader.content, "pauseVideo")();
+ }
+ else
+ {
+ Reflect.field(_youtubeLoader.content, "playVideo")();
+ }
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
{
_stream.togglePause();
}
@@ -968,8 +1219,6 @@ class Player extends EventDispatcher
soundTransform.volume = _volume;
}
- _stream.soundTransform = soundTransform;
-
isMute = false;
}
@@ -984,7 +1233,11 @@ class Player extends EventDispatcher
isMute = true;
}
- if (_type == InputType.VIDEO)
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ Reflect.field(_youtubeLoader.content, "setVolume")(soundTransform.volume * 100);
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
{
_stream.soundTransform = soundTransform;
}
@@ -993,6 +1246,7 @@ class Player extends EventDispatcher
_soundChannel.soundTransform = soundTransform;
}
+
return isMute;
}
@@ -1021,7 +1275,12 @@ class Player extends EventDispatcher
//raise volume if not already at max
if (_volume < 1)
{
- if (_type == InputType.VIDEO)
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ _volume = (Reflect.field(_youtubeLoader.content, "getVolume")() + 10) / 100;
+ Reflect.field(_youtubeLoader.content, "setVolume")(_volume * 100);
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
{
_volume = _stream.soundTransform.volume + (10/100);
soundTransform.volume = _volume;
@@ -1055,7 +1314,12 @@ class Player extends EventDispatcher
//lower sound
if(!_soundMuted)
{
- if (_type == InputType.VIDEO)
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ _volume = (Reflect.field(_youtubeLoader.content, "getVolume")() - 10) / 100;
+ Reflect.field(_youtubeLoader.content, "setVolume")(_volume * 100);
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
{
_volume = _stream.soundTransform.volume - (10/100);
soundTransform.volume = _volume;
@@ -1099,6 +1363,15 @@ class Player extends EventDispatcher
{
_streamType = streamType;
}
+
+ /**
+ * Sets the server url for rtmp streams
+ * @param server
+ */
+ public function setServer(server:String):Void
+ {
+ _server = server;
+ }
/**
* To set a reference to a poster image that should be disabled when media is loaded and ready to play
@@ -1140,7 +1413,11 @@ class Player extends EventDispatcher
soundTransform.volume = volume;
- if (_type == InputType.VIDEO)
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ Reflect.field(_youtubeLoader.content, "setVolume")(soundTransform.volume * 100);
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
{
_stream.soundTransform = soundTransform;
}
@@ -1174,26 +1451,6 @@ class Player extends EventDispatcher
//{Getters
/**
- * Current playtime of the loaded video
- * @return
- */
- public function getTime():Float
- {
- var time:Float = 0;
-
- if(_type == InputType.VIDEO)
- {
- time = _stream.time;
- }
- else if (_type == InputType.AUDIO)
- {
- time = _soundChannel.position / 1000;
- }
-
- return time;
- }
-
- /**
* Gets the volume amount 0.0 to 1.0
* @return
*/
@@ -1252,7 +1509,7 @@ class Player extends EventDispatcher
* @return video object for further manipulation
*/
public function getVideo():Video
- {
+ {
return _video;
}
@@ -1291,7 +1548,12 @@ class Player extends EventDispatcher
{
var bytesTotal:Float = 0;
- if (_type == InputType.VIDEO)
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ if(_youtubeLoader != null)
+ bytesTotal = Reflect.field(_youtubeLoader.content, "getVideoBytesTotal")();
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
{
bytesTotal = _stream.bytesTotal;
}
@@ -1311,7 +1573,12 @@ class Player extends EventDispatcher
{
var bytesLoaded:Float = 0;
- if (_type == InputType.VIDEO)
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ if(_youtubeLoader != null)
+ bytesLoaded = Reflect.field(_youtubeLoader.content, "getVideoBytesLoaded")();
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
{
bytesLoaded = _stream.bytesLoaded;
}
@@ -1333,6 +1600,24 @@ class Player extends EventDispatcher
}
/**
+ * The stream method for the current playing media
+ * @return
+ */
+ public function getStreamType():String
+ {
+ return _streamType;
+ }
+
+ /**
+ * The server url for current rtmp stream
+ * @return
+ */
+ public function getServer():String
+ {
+ return _server;
+ }
+
+ /**
* To check current quality mode
* @return true if high quality false if low
*/
@@ -1348,7 +1633,22 @@ class Player extends EventDispatcher
public function getCurrentTime():Float
{
var time:Float = 0;
- if (_type == InputType.VIDEO)
+ if (_streamType == StreamType.YOUTUBE)
+ {
+ if(_youtubeLoader != null)
+ {
+ time = Reflect.field(_youtubeLoader.content, "getCurrentTime")();
+ }
+ else
+ {
+ time = 0;
+ }
+ }
+ else if (_streamType == StreamType.PSEUDOSTREAM)
+ {
+ time = getStartTime() + _stream.time;
+ }
+ else if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
{
time = _stream.time;
}
diff --git a/src/jaris/player/StreamType.hx b/src/jaris/player/StreamType.hx
index 66f202c..d3b1102 100644
--- a/src/jaris/player/StreamType.hx
+++ b/src/jaris/player/StreamType.hx
@@ -30,4 +30,5 @@ class StreamType
public static var FILE:String = "file";
public static var PSEUDOSTREAM:String = "http";
public static var RTMP:String = "rtmp";
+ public static var YOUTUBE = "youtube";
}
\ No newline at end of file
diff --git a/src/jaris/player/controls/Controls.hx b/src/jaris/player/controls/Controls.hx
index 7196dea..0dd66f6 100644
--- a/src/jaris/player/controls/Controls.hx
+++ b/src/jaris/player/controls/Controls.hx
@@ -58,7 +58,6 @@ class Controls extends MovieClip {
private var _thumb:Sprite;
private var _track:Sprite;
private var _trackDownloaded:Sprite;
- private var _trackBar:Sprite;
private var _scrubbing:Bool;
private var _stage:Stage;
private var _movieClip:MovieClip;
@@ -108,10 +107,6 @@ class Controls extends MovieClip {
_seekBar = new Sprite();
addChild(_seekBar);
- _trackBar = new Sprite( );
- _trackBar.tabEnabled = false;
- _seekBar.addChild(_trackBar);
-
_trackDownloaded = new Sprite( );
_trackDownloaded.tabEnabled = false;
_seekBar.addChild(_trackDownloaded);
@@ -147,8 +142,6 @@ class Controls extends MovieClip {
_seekPlayTimeLabel.text = "00:00:00";
_seekPlayTimeLabel.tabEnabled = false;
addChild(_seekPlayTimeLabel);
-
- drawSeekControls();
//}
//{Playing controls initialization
@@ -182,6 +175,8 @@ class Controls extends MovieClip {
_controlsBar.addChild(_volumeTrack);
//}
+ redrawControls();
+
//{Loader bar
_loader = new Loader();
_loader.hide();
@@ -206,7 +201,6 @@ class Controls extends MovieClip {
_track.addEventListener(MouseEvent.CLICK, onTrackClick);
_track.addEventListener(MouseEvent.MOUSE_MOVE, onTrackMouseMove);
_track.addEventListener(MouseEvent.MOUSE_OUT, onTrackMouseOut);
- _trackBar.addEventListener(MouseEvent.MOUSE_OUT, onThumbMouseUp);
_playControl.addEventListener(MouseEvent.CLICK, onPlayClick);
_pauseControl.addEventListener(MouseEvent.CLICK, onPauseClick);
_aspectRatioControl.addEventListener(MouseEvent.CLICK, onAspectRatioClick);
@@ -275,12 +269,14 @@ class Controls extends MovieClip {
private function onEnterFrame(event:Event)
{
if(_player.getDuration() > 0) {
- if(_scrubbing) {
- _player.seek(_player.getDuration() * (_thumb.x / _track.width));
+ if (_scrubbing)
+ {
+ _player.seek(((_thumb.x - _track.x) / _track.width) * _player.getDuration());
}
- else {
- _currentPlayTimeLabel.text = Utils.formatTime(_player.getTime());
- _thumb.x = (_player.getTime()+_player.getStartTime()) / _player.getDuration() * (_track.width-_thumb.width);
+ else
+ {
+ _currentPlayTimeLabel.text = Utils.formatTime(_player.getCurrentTime());
+ _thumb.x = _player.getCurrentTime() / _player.getDuration() * (_track.width-_thumb.width) + _track.x;
}
}
@@ -434,10 +430,13 @@ class Controls extends MovieClip {
{
if (!_player.isFullscreen())
{
- _player.getVideo().height = _stage.stageHeight - _trackBar.height;
- _player.getVideo().width = _player.getVideo().height * _player.getAspectRatio();
-
- _player.getVideo().x = (_stage.stageWidth / 2) - (_player.getVideo().width / 2);
+ if (_player.getVideo().y + _player.getVideo().height >= _stage.stageHeight)
+ {
+ _player.getVideo().height = _stage.stageHeight - _seekBar.height;
+ _player.getVideo().width = _player.getVideo().height * _player.getAspectRatio();
+
+ _player.getVideo().x = (_stage.stageWidth / 2) - (_player.getVideo().width / 2);
+ }
}
redrawControls();
@@ -490,7 +489,7 @@ class Controls extends MovieClip {
*/
private function onTrackClick(event:MouseEvent)
{
- var clickPosition:Float = _track.mouseX - _currentPlayTimeLabel.width;
+ var clickPosition:Float = _track.mouseX;
_player.seek(_player.getDuration() * (clickPosition / _track.width));
}
@@ -500,10 +499,10 @@ class Controls extends MovieClip {
*/
private function onTrackMouseMove(event:MouseEvent):Void
{
- var clickPosition:Float = _track.mouseX - _currentPlayTimeLabel.width;
+ var clickPosition:Float = _track.mouseX;
_seekPlayTimeLabel.text = Utils.formatTime(_player.getDuration() * (clickPosition / _track.width));
- _seekPlayTimeLabel.y = _stage.stageHeight - _trackBar.height - _seekPlayTimeLabel.height - 1;
+ _seekPlayTimeLabel.y = _stage.stageHeight - _seekBar.height - _seekPlayTimeLabel.height - 1;
_seekPlayTimeLabel.x = clickPosition + (_seekPlayTimeLabel.width / 2);
_seekPlayTimeLabel.backgroundColor = _brightColor;
@@ -546,7 +545,7 @@ class Controls extends MovieClip {
{
_thumb.graphics.lineStyle();
_thumb.graphics.beginFill(_hoverColor);
- _thumb.graphics.drawRect(_currentPlayTimeLabel.width, (_seekBar.height/2)-(10/2), 10, 10);
+ _thumb.graphics.drawRect(0, (_seekBar.height/2)-(10/2), 10, 10);
_thumb.graphics.endFill();
}
@@ -558,7 +557,7 @@ class Controls extends MovieClip {
{
_thumb.graphics.lineStyle();
_thumb.graphics.beginFill(_controlColor);
- _thumb.graphics.drawRect(_currentPlayTimeLabel.width, (_seekBar.height/2)-(10/2), 10, 10);
+ _thumb.graphics.drawRect(0, (_seekBar.height/2)-(10/2), 10, 10);
_thumb.graphics.endFill();
}
@@ -608,12 +607,13 @@ class Controls extends MovieClip {
}
var position:Float = _player.getStartTime() / _player.getDuration();
+ var startPosition:Float = (position * _track.width) + _track.x;
_trackDownloaded.graphics.clear();
-
_trackDownloaded.graphics.lineStyle();
+ _trackDownloaded.x = startPosition;
_trackDownloaded.graphics.beginFill(_brightColor, 0xFFFFFF);
- _trackDownloaded.graphics.drawRect(_currentPlayTimeLabel.width + (position * _track.width), (_seekBar.height / 2) - (10 / 2), _track.width * _percentLoaded, 10);
+ _trackDownloaded.graphics.drawRect(0, (_seekBar.height / 2) - (10 / 2), ((_track.width + _track.x) - _trackDownloaded.x) * _percentLoaded, 10);
_trackDownloaded.graphics.endFill();
}
@@ -624,53 +624,48 @@ class Controls extends MovieClip {
{
//Reset sprites for redraw
_seekBar.graphics.clear();
- _trackBar.graphics.clear();
_track.graphics.clear();
_thumb.graphics.clear();
//Draw seek bar
+ var _seekBarWidth:Float = _stage.stageWidth;
+ var _seekBarHeight:Float = 25;
_seekBar.x = 0;
_seekBar.y = _stage.stageHeight - 25;
- _seekBar.graphics.lineStyle();
- _seekBar.graphics.beginFill(0x000000, 0);
- _seekBar.graphics.drawRect(0, 0, _stage.stageWidth, 25);
- _seekBar.graphics.endFill();
- _seekBar.width = _stage.stageWidth;
- _seekBar.height = 25;
-
- //Draw trackbar
var matrix:Matrix = new Matrix( );
- matrix.createGradientBox(_seekBar.width, 25, Utils.degreesToRadians(90), 0, _seekBar.height-25);
+ matrix.createGradientBox(_seekBar.width, _seekBar.height, Utils.degreesToRadians(90), 0, 0);
var colors:Array<UInt> = [_brightColor, _darkColor];
var alphas:Array<UInt> = [1, 1];
var ratios:Array<UInt> = [0, 255];
- _trackBar.graphics.lineStyle();
- _trackBar.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
- _trackBar.graphics.drawRect(0, 0, _seekBar.width, _seekBar.height);
- _trackBar.graphics.endFill( );
+ _seekBar.graphics.lineStyle();
+ _seekBar.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
+ _seekBar.graphics.drawRect(0, 0, _stage.stageWidth, 25);
+ _seekBar.graphics.endFill();
//Draw current play time label
_currentPlayTimeLabel.textColor = _controlColor;
- _currentPlayTimeLabel.y = _seekBar.height - (_trackBar.height/2)-(_currentPlayTimeLabel.height/2);
+ _currentPlayTimeLabel.y = _seekBar.height - (_seekBar.height/2)-(_currentPlayTimeLabel.height/2);
//Draw total play time label
_totalPlayTimeLabel.textColor = _controlColor;
_totalPlayTimeLabel.x = _seekBar.width - _totalPlayTimeLabel.width;
- _totalPlayTimeLabel.y = _seekBar.height - (_trackBar.height / 2) - (_totalPlayTimeLabel.height / 2);
+ _totalPlayTimeLabel.y = _seekBar.height - (_seekBar.height / 2) - (_totalPlayTimeLabel.height / 2);
//Draw download progress
drawDownloadProgress();
//Draw track place holder for drag
+ _track.x = _currentPlayTimeLabel.width;
_track.graphics.lineStyle(1, _controlColor);
_track.graphics.beginFill(_darkColor, 0);
- _track.graphics.drawRect(_currentPlayTimeLabel.width, (_seekBar.height / 2) - (10 / 2), _seekBar.width - _currentPlayTimeLabel.width - _totalPlayTimeLabel.width, 10);
+ _track.graphics.drawRect(0, (_seekBar.height / 2) - (10 / 2), _seekBar.width - _currentPlayTimeLabel.width - _totalPlayTimeLabel.width, 10);
_track.graphics.endFill();
//Draw thumb
+ _thumb.x = _currentPlayTimeLabel.width;
_thumb.graphics.lineStyle();
_thumb.graphics.beginFill(_controlColor);
- _thumb.graphics.drawRect(_currentPlayTimeLabel.width, (_seekBar.height/2)-(10/2), 10, 10);
+ _thumb.graphics.drawRect(0, (_seekBar.height/2)-(10/2), 10, 10);
_thumb.graphics.endFill();
}
@@ -807,7 +802,7 @@ class Controls extends MovieClip {
/**
* To set the duration label when autostart parameter is false
- * @param duration seconds or formatted string in format hh:mm:ss
+ * @param duration in seconds or formatted string in format hh:mm:ss
*/
public function setDurationLabel(duration:String):Void
{
diff --git a/src/jaris/utils/Utils.hx b/src/jaris/utils/Utils.hx
index 2ffdcc3..58e3f7e 100644
--- a/src/jaris/utils/Utils.hx
+++ b/src/jaris/utils/Utils.hx
@@ -121,4 +121,31 @@ class Utils
return timeString;
}
+
+ public static function rtmpSourceParser(source:String):String
+ {
+ if (source.indexOf(".flv") != -1)
+ {
+ return source.split(".flv").join("");
+ }
+ else if (source.indexOf(".mp3") != -1)
+ {
+ return "mp3:" + source.split(".mp3").join("");
+ }
+ else if (source.indexOf(".mp4") != -1)
+ {
+ return "mp4:" + source;
+ }
+ else if (source.indexOf(".f4v") != -1)
+ {
+ return "mp4:" + source;
+ }
+
+ return source;
+ }
+
+ public static function youtubeSourceParse(source:String):String
+ {
+ return source.split("watch?v=").join("v/");
+ }
}
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/jarisplayer.git
More information about the Pkg-javascript-commits
mailing list