Stop embedded swf file - actionscript-3

I have a video that is in SWF format and I need to have it embedded in another SWF file. This I have no problem with. The video get's embedded, plays when it need, but I can't figure out how to stop it. My code is like this:
var k:Object = new videoClass();
video = k as MovieClip;
parentObject.addChild(video);
Now, when I want to unload the video I call this:
parentObject.removeChild(video);
video.stop();
video = null;
Sadly, the video does unload but I can still hear the sound playing. Any idea how to fix this? Thanks.

[EDIT] Why not use video into a video format, like FLV ? SWF is not as optimized for video as FLV is.
The loaded SWF have only a static video into it's timeline, or have any programming on it?
Maybe you're dealing with a SWF with code which makes it play it's video.
If that's the case, you can access public methods from it and control it.
var video:MovieClip = new videoClass() as MovieClip;
parentObject.addChild(video);
...
video.publicMethodToStopAllMedia();
parentObject.removeChild(video);

Related

Adobe flash Youtube Video

How would i emded a youtube video into a Flash banner, Without the controlls, just a play and pause button on the video and A link to youtube, (it going to be very small.
This i what it needs to look like:
I am using this code now, but i cant se the video due to the bar at the bottom:
import flash.events.MouseEvent;
import flash.net.URLRequest;
Security.allowDomain("www.youtube.com");
var my_player:Object;
var my_loader:Loader = new Loader();
my_loader.load(new URLRequest("http://www.youtube.com/v/wQ-UltJAjMU?version=2"));
//http://www.youtube.com/watch?v=wfU5Hj3uKZ4
//btn_go
btn_go.addEventListener(MouseEvent.CLICK, onLoaderInit);
function onLoaderInit(e:Event):void{
btn_go.visible=false;
addChild(my_loader);
my_player = my_loader.content;
my_player.setSize(106,56);
my_player.addEventListener("onReady");
}
This is what my code makes me:
You need to load the chromeless player (http://www.youtube.com/apiplayer?version=3). Instructions here.
When it's loaded, tell it to play the video you need using player.loadVideoById("wQ-UltJAjMU"). (API reference.)
Edit: or player.cueVideoById("wQ-UltJAjMU") if you need it to load and display the video thumbnail but not start playing automatically.

Flash FLVPlayBack Video goes FULLSCREEN instead of the Application

I am working on a Flash App and its a presentation. I want the App to go full screen but there is an FLVPlayBack component playing a video now instead of the App the StageDisplayState.FULL_SCREEN turns the video to full screen.
When I remove the video it works fine but I need that video there.
Any idea what is going wrong here ?
_Iza
set the fullScreenTakeOver parameter of your FLVPlayback Component to false before the FULL_SCREEN Code. Hope that will resolve that Video takeover issue.
var yourFLVPlaybackComp:FLVPlayback = new FLVPlayback();
yourFLVPlaybackComp.fullScreenTakeOver = false;

AS3 Video & NetStream : MP4 video not showing with appendBytes

I'm trying to stream some MP4 video in a Video component in an Air application, using a NetStream and the netStream.appendBytes method. The source video is coming from a socket so I need to append the Bytes, but it was not working. So I tried to appendBytes from a file read from the system, it still wasn's working. I tried putting that file as the source of a VideoPlayer element, and it did work.
I then tried the appendBytes method to open an flv file from the system and it did work, so I knew I was not doing something wrong in my process. What does VideoPlayer do that I don't when I use the appendBytes method, that would make it work like I want ?
You cannot use appendBytes and mp4 containers. AppendBytes works with FLV frames only.

Autoplay audio on mobile safari

Before I get flamed to death, I know this doesn't work currently due to Apple's concern over downloading an audio file automatically.
However, my question is: Has anyone found a cunning workaround yet? I just want to play a start up sound on the launch of a game and currently have to wait for the user to click somewhere before I can play the audio. One of you clever chaps must have got this working by now?
There is no chance to get autoplay working in mobile browsers. Android and iOS doesn't allow it and personally I think that is a feasible confinement! Imagine every second website you will open plays and ugly sound at start!
But you can make a little hack, so that the user will not remark that he currently started the audio for your application:
You WILL need an user interaction to start your audio. So, your app or game maybe has a startscreen or a welcome button which needs a click to get to mainmenu or start the game. Bind to an user event (the accepted events are: "click", "touchend", "doubleclick" and "keydown") and call the load() method for your <audio>.
Bind to the "canplaythrough" event of the <audio>. This event is triggered when your source is ready to play. Here you can now call play(), pause() or wait for other interactions. So the audio is ready but now you have full controll when to start or stop the sound.
I also advise you to use audio sprites on mobile clients. iOS (and Android?) internally implemented audio support through a Singleton. That means that you cannot, like in desktop browser, have 10 audio elements and play differents sound at once. You can only play one file!
So changing the source for different sounds takes to much time. With an audio sprite you can start your sprites when the user first interact with your website or game. Pause your sprite and when you need to play sound you have to set the currentTime to the beginning of the sprite and pause the sprite when currentTime of your file reaches the end of your sprite. There is an timeupdate Event where your can check the currentTime of your sprite.
If you are more interested I can prepare my javascript audio sprites player for you!!
Only solution I have seen so far is to create a shell app and put the web app inside a UIWebView.
http://flowz.com/2011/03/apple-disabled-audiovideo-playback-in-html5/
UIWebView.allowsInlineMediaPlayback = YES;
UIWebView.mediaPlaybackRequiresUserAction = NO;
I also would really like to know how to do this in a plain-old web app.
I believe I just solved this for my own app.
The steps,
Controller loads up,
Then.... in viewDidLoad
have your web view load the HTML : loadHTMLString:htmlFile baseURL:[self getBasePath]];
THEN... set mediaPlaybackRequiresUserAction = NO on the webview.
If you set it too soon, I think the load for the html resets it.
I have a bot chat app that has voice messages and I needed them to be autoplayed whenever needed ... so here is what worked for me in my angular app :
just attach a click eventlistener to document and call player.load(), after that whenever you set player.src = x; it will autoplay.
<audio id="voicePlayer" controls autoplay playsinline #voicePlayer></audio>
#ViewChild('voicePlayer', { read: ViewContainerRef }) voicePlayerRef: ViewContainerRef;
...
ngAfterContentInit(): void {
this.voicePlayer = this.voicePlayerRef.element.nativeElement;
document.addEventListener('click', this._onDocumentClick.bind(this));
}
_onDocumentClick() {
this.voicePlayer.load();
document.removeEventListener('click', this._onDocumentClick);
}
...
this.voicePlayer.src = 'x';
HowlerJS creates is a workaround. The user doesn't need to allow autoplay for the audio to be played automatically
Explanation from Docs on how this workaround is created :
howler.js is an audio library for the modern web. It defaults to Web Audio API and falls back to HTML5 Audio. This makes working with audio in JavaScript easy and reliable across all platforms.

Play video only after its fully downloaded

Flv seems like can't be use with loader but NetStream. But I wanted to play the video only after I have completely download it (smooth viewing with no buffering time). How can I do it with NetStream? And Can I have multiple video load at same time, and play it according to some array arrangement?
you can check if stream.bytesLoaded == stream.bytesTotal