Determining an initial NetStream buffersize based on bandwidth and bitrate - actionscript-3

I'm trying to determine an initial value for NetStream.bufferTime based on the client's calculated bandwidth and the video's bitrate.
As far as I can tell you can't do this, because you must have an initial buffer set BEFORE you call NetStream.play() (or use the default 2 seconds) and FMS does not call NetStream.onMetaData, where one would normally find the videodatarate, until after NetStream.play() is called.
Even if you modify NetStream.bufferTime during the onMetaData call back it doesn't effect when the video starts playing or when the NetStatus event registers "NetStatus.Buffer.Full".
Therefore my question is:
How do I find the Video Data Rate BEFORE I call NetStream.play?
-Or-
How do how do I reset the initial bufferTime before acctual play back begins and the NetStatus event fires with "NetStatus.Buffer.Full"

Related

What is the default frame rate in cocos2dx

I know that the Node's update method will be called every frame if we call scheduleUpdate for the current node. Is the delta parameter in the update method the same on all devices and platforms? If not, then how can I calculate what the frame rate or the delta value is on the device running my game?
I the AppDelegate you will see a line like below:
director->setDisplayStats(true);
If the value passed down is set to true you will see the frame rate of your game in the bottom left corner. You can follow that code to see how they calculate the FPS, if you want to add constant frame rate functionality to your code.
[EDIT: Based on the comment below]
The way I have done what you want in the past is by having a dedicated game controller which has a scheduled update function and I use that to set a delta value that can be passed around or accessed by other components of the game.

How to identify that html5 media element is stalled and waiting for further media to continue playing

I am working with MediaSource and SourceBuffer to play html5 video. I am sequentially fetching DASH fragments to continue uninterrupted video play. But sometimes, due to network conditions, SourceBuffer runs out of data to continue play. When that data arrives play resumes. But between this period, video looks stalled. I want to add some visual indication over media element, that it is paused as its buffering required data.
I tried binding 'waiting' and 'stalled' events on video, but none of the events get fired.
var vid = $('video')[0];
vid.addEventListener('stalled', function(e) { console.log('Media stalled...');})
Is there any other way to know whether media has been stalled and when it resumes back?
Thanks.
Using the stalled event is correct, but unfortunately, it does not always work as expected.
You could use Media Source Extension which gives you full control of the buffer and allow you to detect stalls manually. However, a solution using that is a bit out of scope here IMO.
You could possible get around using the timeupdate event as well.
Have a setTimeout() running with a time-out value
Inside the timeupdate event, clear this timer and set a new
If the timer isn't reset, it means there is no time progress and if not paused or ended, assume stalling
Example (untested):
...
var timerID = null, isStalling = false;
vid.addEventListener("timeupdate", function() {
clearTimeout(timerID);
isStalling = false;
// remove stalling indicator if any ...
timerID = setTimeout(reportStalling, 2000); // 2 sec timeout
});
// integrate with stalled event in some way -
vid.addEventListener("stalled", function() {isStalling = true})
function reportStalling() {
if ((!vid.paused && !vid.ended) || isStalling) { ... possible stalling ... }
}
...
You may have to do some additional checks to eliminate other possibilities and so forth, but this is only to give you the general idea, and in addition to using the stalling event.
A different approach could be to monitor the loaded buffer segments using the buffered object (see this answer here for example on usage).
These can be used to see if you have any progress, then use currentTime compared with the ranges to see if the time is at the end of a range and/or if the ranges are changing at all.
In any case, hope this give some input.
Here is the reference http://www.w3schools.com/tags/ref_av_dom.asp
I think you are looking for the event suspend: fires when the browser is intentionally not getting media data

Getting "Time Elapsed" of a playing video from the YouTube API in ActionScript 3.0

I am building a YouTube video player in Flash / ActionScript 3.0, using their API.
However I am struggling to find a simple way of getting a play progress indicator. All I am looking for is a numerical display that shows time elapsed / total duration. It doesnt need to be a bar or anything.
After going through the YouTube API, I cant see any kind of event or method from which to get this kind of information.
Without any kind of event the best thing I can think of doing is creating a timer to mimick the time progress, pausing the timer when the video buffer event is triggered, but this seems a bit hacky and wrong.
What is the best way of getting the time elapsed data from the YouTube API?
Yes in the Youtube API there are such informations:
player.getDuration():Number
Returns the duration in seconds of the currently playing video. Note that getDuration() will return 0 until the video's metadata is loaded, which normally happens just after the video starts playing.
If the currently playing video is a live event, the getDuration() function will return the elapsed time since the live video stream began. Specifically, this is the amount of time that the video has streamed without being reset or interrupted. In addition, this duration is commonly longer than the actual event time since streaming may begin before the event's start time.
player.getCurrentTime():Number
Returns the elapsed time in seconds since the video started playing.

AS3: Call external function periodically depending on played video stream

I implemented a flex application to play an incoming video stream from a Red5 Media Server.
private function playStream(streamName:String, offset:int):void {
stream = new NetStream(connection);
stream.play(streamName + ".flv", offset);
var streamVideo:Video = new Video();
streamVideo.attachNetStream(stream);
display.addChild(streamVideo); }
The playStream method plays a given stream from the position which is defined by offset parameter. Now I want to update my page content depending on the played video stream. Or more specifically I want to call an actionscript method that updates the content, after each minute in the video. Should I use Timer for that reason?
Best regards
Yes, you will need to user a Timer object. But don't use the Timer to determine where the user is at in playback of the video. You should use the time property of the NetStream instead.
You should also add an event listener for the NetStatusEvent in your playStream() method. In particular, you want to inspect the info property of this event (technically it's the info.code property). This has several useful messages that you will want to use to know: when the video playback starts/stops/pauses, when the user performs a seek, and so on. This way you can manage your Timer and update the UI efficiently when the user interacts w/the video player.
Some of the relevant codes on the NetStatusEvent are below. But inspect the full list, you might find others that will help you.
NetStream.Pause.Notify (the user paused playback, start/stop the timer here as appropriate)
NetStream.Play.Start (playback started, start the timer)
NetStream.Play.Stop (playback stopped, stop the timer)
NetStream.Seek.Notify (user seeked to a new point, update the UI)

Actionscript 3 NetStream immediately paused does not get metadata

I am writing a basic video player in Flash CS5 and Actionscript 3. For this basic player, I attach my NetStream to my NetConnection, then call the stream's .play() method to begin loading. Although I want the metadata and for the stream to begin buffering, I do not wish to start playing right away, so I immediately call the stream's .pause() method. Unfortunately, when I pause immediately, my stream's client's onMetaData event is not always called, so I don't necessarily get the total playtime of the loaded video.
As a workaround, I put the call to the "pause" method inside the onMetaData listener, but sometimes my video will have played a bit before receiving it's metadata, and will therefore continue to play until it does.
Is there a good way to stop my stream from playing, and still get my video metadata?
Okay, here's a neat little way of thinking about this differently... Do not attach your video object to your stream object right away. Start your stream playing while showing a "please wait" visual WITHOUT your video object being displayed. In your onMetaData listener, see if you have stored a duration previously. If not, assume this is the first call to onMetaData, store the duration, pause playback, seek the stream to 0, THEN attach the video object.
The user will see a "please wait" for just a sec, then the video will appear, paused & ready to be played with it's duration times as expected. The user will be completely unaware that the stream played forward a bit while they were waiting.
You should call pause when the NetStatusEvent.STATUS event NetStream.Play.Start is fired.
Update:
For very short streams (e.g. buffer > duration) NetStream.Play.Start is likely to get fired just before the onMetaData callback.
Before pausing on NetStream.Play.Start, check if metaData has been provided, if not don't pause straight but await onMetaData to pause (just set a flag, e.g pauseOnMetaData = true).