FLVPlayback VideoEvent.COMPLETE triggers before the video reaches the end, and the video stops playing - actionscript-3

import fl.video.*;
var player:FLVPlayback = new FLVPlayback();
addChild(player);
player.skin = "someSkin.swf";
player.source = "http://someDomian/some.flv";
Here's the code. I just load and play some flv from server, and when I test it via Flash (just press ctrl+enter), the video will stop at about 90% of the video and dispatch the COMPLETE event. Any one knows why? Try it again, the time where the video stops is the same, just about 90%.
I searched it, and I tried to change playheadUpdateInterval of player, set totalTime explictly, or set bufferTime longer. All those solutions make no difference.
I tried to load another movie from the same server, same problem. Any chances something wrong with the server?
EDIT:
I sent the swf to someone else, and the video plays as it's supposed to do. Then another guy, and the same result. So, I guess there's something wrong with my settings? Is there some setting will cause this strange action? But when I tried it on my laptop, the video stops unexpectedly. Why this seems to work on everyone's computer except mine?
before CLOSE:
Eventually my colleagues found the strange reason causes this problem, if changing the publish setting to FP10 & 10.1 or FP9, it'll work as we expect. FP10.2 and up, videos on that server seem not have the talent to find their ending. The videos are H.264/AAC, if I convert them to VP60/MP3, all the FP versions will work. Since I can't modify the setting about the codecs, I'll just change the publish setting and leave the codecs thing alone. Although I'm just frustrated by this, if you see this and so lucky that you happen to know the codecs thing why the "early complete" appears, please please tell me.

The problem could be with the .FLV file, sometimes there could be problems while encoding any video file(AVI,MOV,MP4,3GP,WMV) in to .FLV format that results in skipped frames. Try your code with some other .FLV file if that works good then you need to re-encode your FLV file.
You can also try capturing the video Complete Event by tracking the Video Playback Progress.
import fl.video.*;
var player:FLVPlayback = new FLVPlayback();
addChild(player);
player.skin = "someSkin.swf";
player.source = "http://someDomian/some.flv";
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler(event:Event):void {
if(player.playheadPercentage>=99)
{
//On Video Playback Complete Actions here
}
}

Related

As3 - I Simply cannot remove loader child no matter what

I have loaded an external SWF to my timeline using a common loader method. The SWF is Jwplayer and it is polling a live rtmp stream. Here is the snippet I used to load it successfully.
var c4:Loader = new Loader();
var c4req:URLRequest = new URLRequest("player.swf");
var c4flashvars:URLVariables = new URLVariables();
c4flashvars.streamer = "rtmp://myserver";
c4flashvars.file = "live"
c4req.data = c4flashvars;
c4.load(c4req);
addChild(c4)
Now, the player loads fine. It begins to poll a live stream, too. However, no matter what I try I cannot remove this child from the stage. I have tried the following:
removeChild(c4);
c4.unloadAndStop();
For testing, I am calling these from a timer/event listener/function combo. I traced it to make sure it was being fired, and it is. However the player just sits there on the stage and refuses to leave. Output isn't throwing any errors. I half suspect that because it's polling a live stream that the loader never sees the external SWF as fully loaded. But that's just a hunch.
The overall scope of this little project is to load the player, check for an event, and re-load the player (unload, and reload). If anyone could help me understand this, get past this, or is feeling generous enough to show me the light; I'd appreciate it greatly. I've put a solid day into messing around with this and searching. I'm just not grasping something. Thanks!

Memory Efficient Code with WebAudio API

I am developing an HTML5 game and using Web Audio API for sounds. I am having an issue in which sounds start slowing down as game progress and game also starts feeling jerks which i guess is due to java-script GC doing memory cleanup.There are two types of sound i am playing in the game:
1) Background sound which continuously loop
2) Jump sound, hit sound etc occurs due to some event in the game which occurs very frequently. For example: firing multiple bullets from gun.
Not sure what i am doing wrong, please help. Please refer below code
function play(){
this.startTime = this.actx.currentTime;
this.soundNode = this.actx.createBufferSource();
this.soundNode.buffer = this.buffer;
this.soundNode.connect(this.volumeNode);
//If there's no reverb, bypass the convolverNode
if (this.reverb === false) {
this.volumeNode.connect(this.panNode);
}
//If there is reverb, connect the `convolverNode` and apply
//the impulse response
else {
this.volumeNode.connect(this.convolverNode);
this.convolverNode.connect(this.panNode);
this.convolverNode.buffer = this.reverbImpulse;
}
this.panNode.connect(this.actx.destination);
this.soundNode.loop = this.loop;
this.soundNode.playbackRate.value = this.playbackRate;
this.soundNode.start(
this.startTime,
this.startOffset % this.buffer.duration
);
this.playing = true;
}
There's nothing in your code that stands out as specifically memory intensive, apart from the use of the convolver (which can be really expensive and cause bad performance on lower-end devices). I'd try this though:
Try disabling your audio (don't run any of the audio code, don't just mute it). Do you still have the janks in the game visuals? If so, it's not your audio that's the culprit.
Try running your audio but always run it without the convolver. If the jank disappears, the convolver is your culprit. The only thing I could think of there is to try setting the convolver buffer only once and not every call to play().
Try running different profiles in Chrome Dev Tools (JS, Memory, Paints etc.) and try to figure out where the janks come from. https://developer.chrome.com/devtools/docs/cpu-profiling
Good luck!

How to put music in individual scenes and have it change when i select a new scene

Alright I've managed to make an almost web page style thing in flash. I have all the coding to navigate the pages finished, but now I'm having the issue of when I change pages my main page music continues while the other pages music begins. I.,m unsure of how to code this. can anyone help? also I already have click sound effects going for my buttons and they seem to be working fine. Don't know if that helps at all. I'm also using flash cs6 and don't want to go to cc, because the removal of the bone tool.
To stop a sound, you will need to use a SoundChannel object when you tell the sound to play. Then, with the reference to the SoundChannel, you can stop the sound before you exit the section.
// save this reference for later so you can stop the sound when you want..
var mySoundChannel:SoundChannel = mySound.play(); // Get a sound channel.
// Call this later
mySoundChannel.stop();
Without a SoundChannel to control it, the sound object will do its default behavior, which is to play to completion.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundChannel.html

Flash CS6 Importing sounds

I'm working on a Flash project in CS6 and need to import a sound to my library but I'm having endless problems with it. I'm using external files in Actionscript 3.0 (e.g. I cannot do a URLRequest as it won't work externally, need to import)
I'm using a sound that should work, some errors go in that it can't be over 160kbps, this is only at 32 in the MP3 file. I converted it to an AIFF, no success, a WAV? no success.
If it's an MP3 I simply get "Couldn't import "
If it's a AIFF or WAV I get "One or more files were not imported because there was a problem reading them"
Adobe suggest you need to files under 160kbps, all are set at 32kbps to be safe.
Another suggestion said you needed Quicktime 7.7.1 (or newer) and iTunes 10.5.5.3 (or newer) for this to work with an MP3 file. I have Quick 7.7.3 and iTunes 11.0 so I really have no idea of the problem.
Can anyone help, this project needs finished quickly.
Thanks.
John.
Could be to do with bitrates.
I was running into issues with some mp3 files that I had converted from wav using Audacity. It was a specific few that wouldn't work, so I went back to Audacity and compared the working-mp3-yielding wavs to the non-working. I noticed that the working wavs had a bitrate of 44100Hz the non-working had 48000Hz. Setting the project rate ( bottom left corner ) to 44100Hz before exporting yielded mp3s that imported into flash with no problem.
In short:
48000 Hz = naughty
44100 Hz = nice
This is a weird problem here's a simple code snippet that load and play an MP3 sound AS3 doesn't support WAV natively :
//sound object
var sound:Sound = new Sound(new URLRequest("music.mp3"))
var soundChannel:SoundChannel = sound.play();
Hope this help :)
This post is kind of old but I thought I would post an answer after running into the same problem. I am also using Flash Pro in CS6. What you want to do is to embed the sound into your FLA so that when your SWF is compiled the sound will go with it. Khaled's answer is great but this issue needs a little more TLC.
What worked for me was to get an application that edits sound clips. I downloaded the open source 'Audacity.' In the bottom left corner of Audacity you can edit the project rate. Take it down to about 1600 or lower. Then save the project and export the sound as an mp3.
Finally, make sure that your sound clip is in the same folder as your FLA. Import into your FLA (this should work now) and export your sound for actionscript by right clicking the sound in the library, going to properties. Change the name of the class to whatever you want (at least get rid of the '.mp3' from the class name).
Then use the following code (which is different from the typical URL loader for sounds):
//sound is a constructor variable under your document class
public class DocumentClass extends MovieClip
{
var yourSound:yourSoundClass;
public function DocumentClass()
{
init();
}
function init():void
{
yourSound = new yourSoundClass();
}
}
Then play your sound by using yourSound.play(); This technique will embed your sound within the SWF so it will go wherever the SWF goes. I hope that helps anyone who runs into this.

Audio of a specific video swf doesn't stop when I load another URLRequest

I am trying to stop the audio of the video swf and I can't get it to stop. Here is my code for loading the file:
var myLoader:Loader= new Loader();
myLoader.x=420;
myLoader.y=200;
// boolean variable set for use below in our function
var screenCheck:Boolean = false;
//These three linces keep stafe elements the same size, so they don't distort
var swfStage:Stage = this.stage;
video_btn.addEventListener(MouseEvent.CLICK,contentvideo);
function contentvideo (event:MouseEvent):void{
myLoader.load(new URLRequest("prevideo.swf"));
addChild(myLoader);
movie_btn.stop();
movie_btn.visible=false;
}
Now I have other functions that load different URLRequest and when they are loading, the audio keeps playing. Do I have to add a line of code to them? I also have an MP3 player and tried SoundMixer.stopAll(). I still need the mp3 player to keep playing.
I'm not familiar with what you're doing but just looking at the code and given the problem you're experiencing I wonder if that
addChild(myLoader);
has anything to do with it. It seems like the kind of thing that could easily create multiple child objects which is why you continue to experience the sound play back. Is there a removeChild[0] option or something?
A shot in the dark I know but I thought I'd offer the possibility anyway.