Why NetStream#togglePause() do not work? - actionscript-3

I create a record audio application based on red5 0.9 version.
Below is my flex client code snippets. My red5 server work fine.
private var playStream:NetStream;
private function playRecord(event:MouseEvent):void{
if(isPausing){
playStream.togglePause();
}else{
playStream=getStream();
playStream.bufferTime=15;
playStream.play(streamName);
}
}
private function pauseRecord(event:MouseEvent):void{
playStream.togglePause();
}
I press pause button fine, but when i press play button, the audio always play form the begining.
Why? do i need to clean up NetStream Buffer?

I found solution myself.
playStream.maxPauseBufferTime=0;

Related

How to properly dispose of an HTML5 Video and close socket or connection

I am building a web page with a list of video records. Clicking on each video record opens a modal dialog on the same page with detail of the record and an HTML5 Video player.
A user can open one video, close it, and open another as many times as they want. However, on Chome specifically, after 3-5 videos, the browser starts hanging for upwards of two minutes while displaying a message "waiting for socket".
Doing some reading, I have narrowed it to Chrome's inability to open more than 6 connections to the same host.
I must be doing something wrong with how I dispose of the Media players. I believe the socket remains open to the media for some period even though the html for the player has been removed from the dom.
Using:
Bootstrap,
MediaElement.js,
HTML5 Video,
MVC,
Controller returning "Range Request" of FilePathResult
// Handling Bootstrap Modal Window Close Event
// Trigger player destroy
$("#xr-interaction-detail-modal").on("hidden.bs.modal", function () {
var player = xr.ui.mediaelement.xrPlayer();
if (player) {
player.pause();
player.remove();
}
});
I am going to go for my Self Learner badge, here, and answer my own question.
I did about 8 hours of research on this and came up with a great solution. Three things had to be done.
Set the HTML5 video src to something other than the original URL. This will trigger the player to close the open socket connection.
Set the HTML5 video src to a Base64 encoded data object. This will prevent the Error Code 4 issue MEDIA_ERR_SRC_NOT_SUPPORTED.
For issues in older versions of Firefox, also trigger the .load() event.
My Code:
// Handling Bootstrap Modal Window Close Event
// Trigger player destroy
$("#xr-interaction-detail-modal").on("hidden.bs.modal", function () {
var player = xr.ui.mediaelement.xrPlayer();
if (player) {
player.pause();
("video,audio").attr("src","data:video/mp4;base64,AAAAHG...MTAw");
player.load();
player.remove();
}
});
I came up with the idea to load the data object as the src. However, I'd like to thank kud on GitHub for the super small base64 video.
https://github.com/kud/blank-video
Added a line between pause() and remove():
// Handling Bootstrap Modal Window Close Event
// Trigger player destroy
$("#xr-interaction-detail-modal").on("hidden.bs.modal", function () {
var player = xr.ui.mediaelement.xrPlayer();
if (player) {
player.pause();
("video,audio").attr("src", "");
player.remove();
}
});

Recording using Flex/Flash

I know that we can not record/Access anything out of flash player, because of it's security sandbox.
Instead We can record the video while streaming it to server.
like
netStream.publish("YourFileName.flv","record");
But in recorde file, I will get only a video file Published by webcam to server and i want to record entire session.
Is there any way to record it locally, or Can i record the window ??
p.s. : I am not trying to access anything outside of flash player.
Thanks in advance...
ok, so you can record the entire contents of the swf like this:
first, create a container object (anything that extends DisplayObject which implements IBitmapDrawable) then place everything that you want to capture (video view and everything else in your "session") then using an ENTER_FRAME event or Timer (preferable to control capture fps), draw the container to a BitmapData using BitmapData.draw(container). Pass that BitmapData to the FLV encode library found here using it's addFrame() method (docs and examples come with that library... super easy) and that's it! When you are done, you will have an flv video containing a frame by frame "screen capture" of what was going on in your swf! Just make sure EVERYTHING is in the container! That lib also accepts captured audio too if you want.
private function startCapturing():void{
flvEncoder.start(); // see the libs docs and examples
var timer:Timer = new Timer(1000/15); //capture at 15 fps
timer.addEventListener(TimerEvent.Timer, onTimer);
timer.start();
}
private function onTimer(event:TimerEvent):void{
var screenCap:BitmapData = new BitmapData(container.width, container.height);
screenCap.draw(container);
flvEncoder.addFrame(screenCap); // see the libs docs and examples
}

AS3 On video end transfer to a new SWF?

I'm trying to make it so once my my video ends the player will be moved onto a new SWF.
Here's the code I created
import fl.video.VideoEvent;
stop();
BackgroundVid.addEventListener(Event.COMPLETE, Menu_Screen);
function Menu_Screen(event:MouseEvent):void
{
var Menu_Screen_Loader = new Loader();
Menu_Screen_Loader.load(new URLRequest("Menu_Screen.swf"));
addChild(Menu_Screen_Loader);
}
Can't figure out why it's not booting properly.
Ok, first of all fix the mistake in the event handler. You are saying that the Event expected is a MouseEvent, where as it will in fact be a plain old Event.
Then if it still doesn't work, you'll need to furnish a bit more info regarding what isn't happening. What do you mean by booting properly. Is your video playing?

Pause/Play functionality from one button?

Could someone tell me what I'm doing wrong here? I'm trying to use one icon in the Windows Phone Application Bar to enable a user to tap it to play and pause background audio that I've inserted as a MediaElement in the XAML. This is my code:
private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState)
{
BackgroundAudioPlayer.Instance.Pause();
}
else if (PlayState.Paused == BackgroundAudioPlayer.Instance.PlayerState)
{
BackgroundAudioPlayer.Instance.Play();
}
It makes sense reading it through and does not throw up any errors when building, however when I tap it whilst testing on my device, the music does not pause and carries on playing (I've set AutoPlay = true to achieve this) Could someone tell me what I should do to enable one button to control play and pause functionality?
Also if I remove the "else if" and make the code into a simple "else" so it looks like this:
private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState)
{
BackgroundAudioPlayer.Instance.Pause();
}
else
{
BackgroundAudioPlayer.Instance.Play();
}
}
it pauses, but does not resume to play!
Here is the step by step implementation to achieve play/pause functionality
click and get solution
"I've inserted as a MediaElement in the XAML."
If you are using a MediaElement, I think you are playing the audio in the foreground. Try closing out of your app after the audio starts. Does it keep playing? To pause and play a media element you can just use the play and pause methods on the media element.
nameOfMediaElement.Pause();
nameOfMediaElement.Play();
To use the event handlers that use the BackgroundAudioPlayer.Instance.PlayerState, you have to setup the initial audio playing back in the background. For this you need to start the audio playback via the BackgroundAudioPlayer.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.backgroundaudio.backgroundaudioplayer(v=vs.105).aspx
Try this.
if(mediaelement.CurrentState == MediaElementState.Paused)
{
mediaelement.Play();
}
else
{
mediaelement.Pause();
}
Hope it works for you.

Action Script navigateToURL not working with stage3d

this simple code is not working for me :
stage.addEventListener(MouseEvent.CLICK, OnClick);
protected function OnClick(e:MouseEvent)
{
navigateToURL(new URLRequest("http://www.stackoverflow.com"), "_blank");
}
later i want url to open from flascc but that can be easily done if this works,
if this is because of security reason then is there any other way to do this? i saw in game called decision 2 their urls work even in debug version flash player + in all browsers. so there must be some other way to do this if navigateToURL dosent work.
Add the folder f:\flascc (or all disk f:) to the flash trusted locations in the security panel (you can also open this panel by the right click on any swf opened in the browser)