I am just starting a video project and have a need to react accurately at specified points in an mp4 video.
There used to be the functionality to add cue points to flv videos but I don't think this is available for flashh cc and mp4.
What other technique would anyone recommend to accurately react to a certain point in the video.
Thanks
I believe that you can still add cue points when using mp4 with the following method:
var cueTime:Number = 20;
var cueName:String = "Chapter1"
var player:FLVPlayback = new FLVPlayback();
player.source = "myMovie.mp4";
player.addASCuePoint(cueTime, cueName);
player.addEventListener(MetadataEvent.CUE_POINT, CuePointHandler);
function CuePointHandler(eventObject:MetadataEvent):void{
if (eventObject.info.name == cueName) {
//Do something
}
}
Related
I am in desperate need of help! I have a mute toggle button that I made following a tutorial on youtube in Adobe Animate/Flash using action-script 3.0 and it mutes everything as it is supposed to. However, I now need it to only mute the background music as it is muting my videos as well! How can I alter the code to either make sure only the background sound is muted and not the video?
function setMute(vol)
{
var sTransform:SoundTransform = new SoundTransform(1,0);
sTransform.volume = vol;
SoundMixer.soundTransform = sTransform;
}
var Mute:Boolean = false;
mute_btn.addEventListener(MouseEvent.CLICK,toggleMute_btn);
function toggleMute_btn(event:Event){ if(Mute)
{
Mute = false; setMute(1);
soundLines.gotoAndStop(1);
}
else
{ Mute = true; setMute(0);
soundLines.gotoAndStop(2);
}
}
In Adobe Animate (AS3), a developer can add audio in mainly two ways, timeline audio and external audio loaded by script. There can be even more methods of adding sound to a Flash movie.
In case of timeline audio, which are embedded and plays on movie progress, you may simply stop that movieclip containing that audio causing mute-like effect for that specific audio.
Example:
If your movieclip named BG contains your background music, you can write BG.stop(); for mute and BG.play(); for resuming the audio. This is the easiest method of all.
In case of streaming audio from external source using code,
var bg:Sound = new Sound();
var bgChannel:SoundChannel = new SoundChannel();
bg.load(new URLRequest("test.mp3"));
bgChannel = bg.play();
function vol(v:uint){
var sT:SoundTransform = new SoundTransform();
sT.volume = v;
bgChannel.soundTransform=sT;
}
setTimeout(vol,1000,0);
Similarly, set vol to higher value for unmute.
I have a 1920x1080 video playing inside a flash project with the same dimensions, using Firefox. The project is using CC2015, Latest Flash Player, Latest FF. I should note that this project is using locally stored videos.
I'm using AS3, FLVPlayback component, and the videos have been compressed (by production).
Heres the code that uses the playback component
function playVideoByString(source: String): void {
hideTheButtons();
attractTimer.stop();
movie_container = new MovieClip();
addChild(movie_container);
movie_container.x = 0;
movie_container.y = 0;
launchVideo(movie_container, source);
}
function launchVideo(vBox, vFile): void {
attractTimer.stop();
flvPlayer = new FLVPlayback();
flvPlayer.source = vFile;
flvPlayer.skinAutoHide = true;
flvPlayer.skinBackgroundColor = 0x000000;
flvPlayer.width = 1920;
flvPlayer.height = 1080;
flvPlayer.autoRewind = false;
cuePt.time = 0.9;
cuePt.name = "ASpt1";
cuePt.type = "actionscript";
flvPlayer.addASCuePoint(cuePt);
vBox.addChild(flvPlayer);
// adding listeners in here
flvPlayer.addEventListener(MetadataEvent.CUE_POINT, cp_listener);
flvPlayer.addEventListener(fl.video.VideoEvent.COMPLETE, completeHandler);
}
Playback is experiencing some degradation in the form of what looks like frames dropping, or "stutter." The animations look glass smooth when the MP4 is opened in Firefox and played back using FFs player. They also look fine when played in QuickTime (obviously). The video is 30FPS, as is the Flash Project, though from what I understand, FLVPlayback will use the videos encoded frame rate regardless of Flash's FPS.
Is there anything I can do to improve the video playback, and possibly smooth the videos out without loosing quality?
I'm creating the soundtrack for a video which consists of an intro sound clip, a looping middle one, and an end clip. I need to write these dynamically to a ByteArray and then combine them with bitmaps to make a video. It's working, except in the video output I get a tiny delay between the intro sound ending and the loop sound beginning (the audio files do not have any silence, they are seamless) - can anyone advise how I could avoid this? (_soundIntro, _soundLoop and _soundEnd are the embedded audio files.)
var baAudio:ByteArray = new ByteArray();
var baAudioIntro:ByteArray = new ByteArray();
var baAudioLoop:ByteArray = new ByteArray();
var baAudioEnd:ByteArray = new ByteArray();
var totalLength:Number = (_bitmaps.length / FLV_FRAMERATE) * 44000;
var loopLength:Number = totalLength - (_soundIntro.length * 44.1) - (_soundEnd.length * 44.1);
_soundIntro.extract(baAudioIntro, _soundIntro.length * 44.1);
_soundLoop.extract(baAudioLoop, loopLength);
_soundEnd.extract(baAudioEnd, _soundEnd.length * 44.1);
baAudio.writeBytes(baAudioIntro);
baAudio.writeBytes(baAudioLoop);
baAudio.writeBytes(baAudioEnd);
Indeed, the answer was that .mp3 encoding outside of flash tends to leave gaps at the beginning and end of audio clips, preventing a seamless loop/transition (http://www.netalive.org/swsu/archives/2007/01/gapless_mp3_loops_in_flash_1.html)
I switched to .wav files, imported to Flash (thus letting Flash handle the encoding) and it fixed the issue.
I am playing looped FLVs in the "standard way":
netstream.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
...
public function onStatus(item:Object):void {
if (item.info.code == "NetStream.Play.Stop") {
if (loop) netstream.seek(0);
}
When played through Flash CS 5.5 authoring tool (Test Movie or Debug Movie), the videos loop seamlessly. But! When played in the browser or standalone debug Flash player (both v.11.2.202.233) there is an abnormal pause of about 1 sec before the video "rewinds".
Is this a bug with the latest Flash player?
For People who have the same issue, try changing the aforementioned code to this:
public function onStatus(item:Object):void {
if (item.info.code == "NetStream.Buffer.Empty") {
if (loop) netstream.seek(0);
}
It will get rid of the flicker. If you listen to "NetStream.Play.Stop", it will cause a flicker.
You don't need to embed anything. This works just fine on IOS, Android and PC.
This is a known bug with Flash Player 11+ and AIR 3+. Bug report is here, and you should upvote & : https://bugbase.adobe.com/index.cfm?event=bug&id=3349340
Known workarounds that will create a seamless loop:
1) Embed the video in the SWF. Not ideal, and not possible in some cases.
2) Create dual NetSteam objects and switch between them. An example of the event fired when ns1, the first of two NetStreams objects, reaches it's end:
if (e.info.code == "NetStream.Play.Stop"){
vid.attachNetStream(ns2);
ns2.resume();
activeNs = ns2;
ns1.seek(0);
ns1.pause();
}
Replace ns1 with ns2 on the other event listener. A useless duplication of objects and handlers, but there you go.
3) Use AIR 2.x / Flash Player 10.x (not really a solution at all, except for Linux users)
We noticed this on the transition from Flash 10 to to Flash 11. Flash 10 loops seamlessly, but Flash 11 has a ~1 second stall when calling seek(0) from NetStream.Play.Stop.
Embedding the media in the SWF is not an option for us.
The following code provides a more seamless loop - still not perfect, but much better.
var mStream:NetStream;
var mDuration:Number;
...
addEventListener(Event.ENTER_FRAME, onEnterFrame);
...
function onEnterFrame(e:Event):void
{
if( mStream.time > (mDuration-0.05) )
{
if( mLooping )
{
mStream.seek(0);
}
}
}
function onMetaData(info:Object)
{
mDuration = info.duration;
}
Hope it helps.
I seem to have achieved this using an FLVPlayback component along with a few tips.
What's more, it's running seamlessly on desktop, iPhone 4S and 3GS! (via an AIR app)
_videoFLV = new FLVPlayback();
_videoFLV.fullScreenTakeOver = false;
_videoFLV.autoPlay = false;
_videoFLV.autoRewind = true;
_videoFLV.isLive = false;
_videoFLV.skin = null;
_videoFLV.y = 150;
_videoFLV.bufferTime = .1;
_videoFLV.width = 320;
_videoFLV.height = 320;
_videoFLV.addEventListener(MetadataEvent.CUE_POINT, video_cp_listener, false, 0, true);
_videoFLV.source = "includes/10sec.flv";
addChild(_videoFLV);
With the listener function...
function video_cp_listener(eventObject:MetadataEvent):void {
if (eventObject.info.name == "endpoint") {
_videoFLV.seek(0);
_videoFLV.play();
}
}
Importantly I think you must set the width and height to match your flv file. i.e. no scaling whatsoever.
The flv has a cue point named 'endpoint' added 1 frame before the end of the file (assuming your start and end frame are the same this will be required).I added this using Adobe Media Encoder.
The only way to loop an flv seamlessly is to embed inside the swf. It is converted to a MovieClip and you then handle it with play(), stop(), nextFrame(), prevFrame() etc.
When embedding in Flash Authoring tool (dragging flv file on stage), make sure that you select:
"Embed FLV in SWF..."
Symbol Type : "Movie clip"
All checked : "Place instance on stage", "Expand timeline...", "Include audio"
I have a website in ActionScript 3 that has lots of FLV animations that happen when you press buttons. Right now this is how I have it set up.
in AS3,
im loading FLv's (which are animations I exported in FLV form from After Effects)
with net stream. I have a timer set up for the same amount of length of time that the animations (FLV's) play and when the timer stops it calls a function that closes the stream, opens a new one and plays another video. The only problem I noticed using timers is that if the connection is slow and (animation)stops for a second, the timer keeps going, and calls the next flv too early.
Does anyone know a way to load a flv, or swf for that matter, at the end of play of the flv? so that the next FLV will always play at the end of the run time of the previous FLV, rather than using timers?
im thinking onComplete but I don't know how to implement that!?
Sequential playing is pretty easy to achieve with the OSMF framework, you should check it out. Google "osmf tutorials" and you should find a few tutorials online.
The framework is fairly recent, but it looks like it may become the de facto solution for media delivery in Flash as it's not limited to video but also audio & images.
As a developer you won't have to bother with the NetStream & NetConnection classes. Developing video solutions , as well as audio & images solutions should be streamlined and easier to handle. Only limitation is that it requires Flash 10
Here's some code for checking when a FLV ends with NetStream. I just provide snippets as I assume you got the FLV up and running already.
//create a netstream and pass in your connection
var netStream:NetStream = new NetStream(conn);
//add callback function for PlayStatus -event
var client : Object = {};
client.onPlayStatus = onPlayStatus;
netStream.client = client;
//attach your NetStream to the connection as usual
//---
//function that gets called onPlayStatus
function onPlayStatus(info : Object) : void {
trace("onPlayStatus:" +info.code + " " + info.duration);
if (info.code == "NetStream.Play.Complete") {
//play the next FLV and so on
}
}
EDIT: With your example code it will look something like this.
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var listener:Object = new Object();
listener.onMetaData = function(md:Object):void{};
listener.onPlayStatus = function(info : Object) : void {
trace("onPlayStatus:" +info.code + " " + info.duration);
if (info.code == "NetStream.Play.Complete") {
//play the next FLV and so on
}
};
ns.client = listener;
vid1.attachNetStream(ns);
const moviename1:String = "moviename2.flv";
const moviename1:String = "moviename3.flv";
var movietoplay:String = "moviename.flv";
ns.play(movietoplay);