corrie.potter
02-04-2009, 02:40 PM
I am having trouble controling the sound using the wowza media server. Here is the code that they use to make all their connections. They use videoObj instead of the flvPlayback component. I do not know what to target to control the volume of the video being played back. I tried targeting the videoObj no luck, nsPlay noluck. Anyone have any ideas?
corrie.potter
02-04-2009, 02:41 PM
import flash.geom.*;
var nc:NetConnection;
var nsPlay:NetStream = null;
var serverName:String = "rtmp://xxx.xxx/simplevideostreaming";
var movieName:String = "test/walk";
var duration:Number = 0;
var progressTimer:Number = 0;
var isPlaying:Boolean = true;
var isProgressUpdate:Boolean = false;
var fastSettings:Array = new Array();
var currFastDir:Number = 0;
var currFastIndex:Number = 0;
var scrubTimer:Number = 0;
var isScrubbing:Boolean = false;
var scrubTime:Number = 0;
var scrubIsPlaying:Boolean;
var stageListener:Object = new Object();
var saveVideoObjX:Number;
var saveVideoObjY:Number;
var saveVideoObjW:Number;
var saveVideoObjH:Number;
var adjVideoObjW:Number;
var adjVideoObjH:Number;
var videoSizeTimer:Number = 0;
var videoLastW:Number = 0;
var videoLastH:Number = 0;
var fullscreenCapable:Boolean = false;
var hardwareScaleCapable:Boolean = false;
//_________CJP VARIABLES _______\\
var stageW:Number = Stage.width;
var stageH:Number = Stage.height;
var flvHeight:Number;
var flvWidth:Number;
var intVidW:Number;
var intVidH:Number;
var allArray:Array = new Array();
function mainInit()
{
// get movie name from parameter is defined
if (_root.zmovieName != undefined)
movieName = _root.zmovieName;
// initialize player control events
_root.mc_controls.fp_PlayPauseButton.onPress = _root.doPlayToggle;
//_root.controls.doPlay.onPress = _root.doPlayToggle;
_root.mc_controls.doRewind.onPress = _root.doRewind;
_root.mc_controls.slider.onPress = _root.startScrub;
_root.mc_controls.slider.onRelease = _root.stopScrub;
_root.mc_controls.slider.onReleaseOutside = _root.stopScrub;
// uncomment this to monitor frame rate and buffer length
//setInterval(_root, "updateStreamValues", 500);
_root.connect.connectStr.text = serverName;
_root.connect.streamStr.text = movieName;
_root.connect.connectButton.onPress = _root.doConnect;
_root.mc_controls.doFullscreen.onPress = _root.enterFullscreen;
enablePlayControls(false);
stageListener.onFullScreen = enterLeaveFullscreen;
Stage.addListener( stageListener );
//adjVideoObjW = (saveVideoObjW = videoObj._width);
//adjVideoObjH = (saveVideoObjH = videoObj._height);
videoObj._visible = false;
fullscreenCapable = testVersion(9, 0, 28, 0);
hardwareScaleCapable = testVersion(9, 0, 60, 0);
}
this.createTextField("time_txt", 10000, 10, 10, 100, 22);
time_text.textColor = 0xFF0000;
time_txt.text = "LOADING";
var time_interval:Number = setInterval(checkTime, 1000);
function checkTime() {
var ns_seconds:Number = nsPlay.time;
var minutes:Number = Math.floor(ns_seconds/60);
var seconds = Math.floor(ns_seconds%60);
if (seconds<10) {
seconds = "0"+seconds;
}
time_txt.text = minutes+":"+seconds;
trace(minutes+":"+seconds);
}
function doConnect()
{
// connect to the Wowza Media Server
if (nc == null)
{
enablePlayControls(true);
nc = new NetConnection();
nc.onStatus = function(infoObject)
{
statusCode_txt.text = infoObject.code;
trace("nc.onStatus: "+infoObject.code+" ("+infoObject.description+")");
for (var prop in infoObject)
{
trace("\t"+prop+":\t"+infoObject[prop]);
}
// once we are connected to the server create the nsPlay NetStream object
if (infoObject.code == "NetConnection.Connect.Success")
{
enablePlayControls(true);
createPlayStream();
videoLastW = 0;
videoLastH = 0;
videoSizeTimer = setInterval(_root, "updateVideoSize", 500);
}
else if (infoObject.code == "NetConnection.Connect.Failed")
_root.prompt.text = "Connection failed: Try rtmp://[server-ip-address]/simplevideostreaming";
else if (infoObject.code == "NetConnection.Connect.Rejected")
_root.prompt.text = infoObject.description;
}
nc.connect(_root.connect.connectStr.text);
// uncomment this to monitor frame rate and buffer length
//debugInterval = setInterval(_root, "updateStreamValues", 500);
_root.connect.connectButton.label = "Stop";
}
else
{
setProgress(0);
videoObj.attachVideo(null);
videoObj.attachAudio(null);
videoObj.clear();
videoObj._visible = false;
if (videoSizeTimer)
clearInterval(videoSizeTimer);
videoSizeTimer = 0;
videoLastW = 0;
videoLastH = 0;
duration = 0;
nc.close();
nc = null;
if (debugInterval > 0)
clearInterval(debugInterval);
debugInterval = 0;
enablePlayControls(false);
_root.connect.connectButton.label = "Play";
_root.prompt.text = "";
}
}
function enablePlayControls(isEnable:Boolean)
{
_root.controls.doPlay.enabled = isEnable;
_root.mc_controls.doRewind.enabled = isEnable;
_root.mc_controls.doFullscreen._visible = isEnable & fullscreenCapable;
}
// function to monitor the frame rate and buffer length
function updateStreamValues()
{
var newVal:String = "";
if (nsPlay != null)
newVal = (Math.round(nsPlay.currentFps*1000)/1000)+" fps/"+(Math.round(nsPlay.bufferLength*1000)/1000)+" secs";
fpsText.text = newVal;
}
// create the nsPlay NetStream object
function createPlayStream()
{
nsPlay = new NetStream(nc);
nsPlay.onStatus = function(infoObject)
{
trace("onStatus: ");
for (var propName:String in infoObject)
{
trace(" "+propName + " = " + infoObject[propName]);
}
if (infoObject.code == "NetStream.Play.Start")
_root.isProgressUpdate = true;
else if (infoObject.code == "NetStream.Play.StreamNotFound" || infoObject.code == "NetStream.Play.Failed")
_root.prompt.text = infoObject.description;
};
nsPlay.onMetaData = function(infoObject:Object)
{
trace("onMetaData");
// print debug information about the metaData
for (var propName:String in infoObject)
{
trace(" "+ propName + " = " + infoObject[propName]);
_root.allArray[propName] = infoObject[propName];
}
flvWidth = _root.allArray.width;
flvHeight = _root.allArray.height;
//error correction for missing metadata
if(flvWidth == undefined) {
trace("flvWidth undefined and reset" + newline);
flvWidth = 320;
}
if(flvHeight == undefined) {
trace(newline + "flvHeight undefined and reset");
flvHeight = 240;
}
// grab the movies duration from the metadata
if (_root.duration == 0)
{
_root.duration = infoObject.duration;
progressTimer = setInterval(_root, "updateProgress", 250);
}
//resize to fit stage
adjVideoObjH = ((stageW)*(flvHeight))/flvWidth;
//trace("newHeight: " + newHeight);
adjVideoObjW = stageW;
saveVideoObjX = videoObj._x;
saveVideoObjY = videoObj._y;
//trace("newWidth: " + newWidth);
videoObj._height = adjVideoObjH;
videoObj._width = adjVideoObjW;
trace(" adjVideoObjH: " + adjVideoObjH);
trace(" adjVideoObjW: " + adjVideoObjW);
};
// print debug information when we encounter a cuePoint
nsPlay.onCuePoint = function(infoObject)
{
trace("onCuePoint: "+infoObject.name+" ("+infoObject.type+")");
for(param in infoObject.parameters)
{
trace(" param: "+param+"="+infoObject.parameters[param]);
}
};
// print debug information when we play status changes
nsPlay.onPlayStatus = function(infoObject:Object)
{
trace("onPlayStatus");
for (var prop in infoObject)
{
trace("\t"+prop+":\t"+infoObject[prop]);
}
};
// set the buffer time and attach the video and audio
nsPlay.setBufferTime(3);
_root.videoObj.attachVideo(nsPlay);
_root.videoObj.attachAudio(nsPlay);
// start playback
_root.isProgressUpdate = false;
_root.isPlaying = true;
nsPlay.play(_root.connect.streamStr.text);
}
// play video (no fast play)
function doPlay()
{
currFastDir = 0;
currFastIndex = 0;
trace("doPlay");
var timecode:Number = nsPlay.time;
_root.isProgressUpdate = false;
if (!_root.isPlaying)
nsPlay.pause(false);
nsPlay.seek(timecode);
_root.isPlaying = true;
}
// event for clicking the play button
// if we are paused or in fast play mode just play the video
// else pause the video
function doPlayToggle()
{
if (!isPlaying){
doPlay();
_root.mc_controls.fp_PlayPauseButton.play_mc._visi ble = false;
}
else
{
_root.isProgressUpdate = false;
_root.isPlaying = false;
nsPlay.pause(true);
_root.mc_controls.fp_PlayPauseButton.play_mc._visi ble = true;
}
}
// rewind to the beginning of the movie and start playing
function doRewind()
{
_root.isProgressUpdate = false;
nsPlay.seek(0);
}
// update the progress bar
function setProgress(timecode:Number)
{
var totalWidth:Number = mc_controls.slider.sliderBack._width;
var newTimecode:Number = timecode;
var newWidth = (totalWidth*newTimecode)/duration;
if (newWidth > totalWidth)
newWidth = totalWidth;
if (!_root.isScrubbing && _root.isProgressUpdate)
mc_controls.slider.sliderSlide._width = newWidth;
}
function updateProgress()
{
setProgress(nsPlay.time);
}
mainInit();
setProgress(0);
doConnect();
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.