Actionscript 3 NetStream immediately paused does not get metadata - actionscript-3

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).

Related

TVML resumable player (in tvOS 14)

I have a TVML/TVJS app that presents a document with a number of playable items. Each item is a lockup element with an event handler to launch the built-in media player, very much like in the example project:
https://developer.apple.com/documentation/tvmljs/playing_media_in_a_client-server_app
In the example code, the event handler creates a new Player object from scratch every time it is triggered, but I would like the player to be resumable: when the user exits the player (e.g. with the menu button) and returns by selecting the item again, I would like to resume the player where it left off.
Before, I would do this by creating Player objects for each item already when the document is loaded (including Playlist and MediaItem), and just execute player.select() or player.play() in the event handler. That would work well.
Since tvOS 14, creating all these Player objects when the document loads seems to overload the app (perhaps it already starts fetching all these items from the network). So I no longer create the Player objects beforehand, but I check in the event handler if I already have a Player for the item, and I create it when it's the first time, otherwise I reuse the Player object.
But even though I checked that I reuse the existing Player object, calling play() or present() causes the playback to restart from the beginning. So what would be the appropriate way to obtain a resumable player?

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)

alert client when live stream is done in AS3

I thought that it was the NetStream.Play.UnpublishNotify in the NetStatusEvent but that doesn't get fired when I stop the live stream. The onFCUnsubscribe event does get fired, however, I have a 5 second buffer and it doesn't wait for that buffer. It gets that event almost instantly. What is the correct way to alert a user that the stream is finished?
The Netstream.Play.Stop is fired when the stream finishes playing.
Have a look here.
http://flash-reference.icod.de/NetStream.html

Recording sound with actionscript3 without waiting for mic activity to begin writing the bytearray

I am testing sound recording in as3 and now i have this question :
I am using this line to start the recording and write sound data to the bytearray (wich works) :
_mic.addEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio);
But the thing is that the sound only start to get written when there is some activity on the mic...
For example, let say i use a "rec" button and click it, i want the bytearray to be filled as soon as the button is clicked...not waiting for mic activity...
So, is it possible to fill a bytearray with "no sound" and how would that be done?
Thanks for any help you can bring!
Just adjust the microphone settings so that there is ALWAYS activity on it as long as you're running it. You do this by adjusting settings like microphone.silenceLevel:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Microphone.html#setSilenceLevel()
So for example, you set the silence level to 0 and the timeout to 99999 or something. This way flash will no longer automatically shut off the microphone when there is no or low sound.