1 Reply Latest reply on Feb 25, 2010 2:48 PM by kglad

    How do i make audio to stop playing soon after loading

    Venkat_SV

      Hi All,  I am new to Flash action script and i have problem with action script code. Even though i comment the mvMyVid.play(); still the audio plays for fraction of second and stops. Can any one help me to tell how the audio plays with out play function. Here is my action script.

       


      import fl.video.*;
      import fl.events.SliderEvent;

      var VOLUME = "volume";
      var myLso:SharedObject = SharedObject.getLocal("PlayerSettings","/");
      var volumeMedia = myLso.data.volume;
      var bLengthMedia = myLso.data.bufferlength;
      var URLLso:SharedObject = SharedObject.getLocal("URLSettings","/");
      var urlType = URLLso.data.protocol;
      var ipAddress = URLLso.data.ipaddress;


      if(volumeMedia == undefined){
      volumeMedia = 1;
      }
      if(bLengthMedia == undefined){
      bLengthMedia = 0.1;
      }
      if(urlType == undefined){
      urlType = "Remote Media";
      }
      if(ipAddress == undefined){
      ipAddress = "";
      }

      this.loaderInfo.addEventListener(Event.INIT, initHandler);
      playBtn.addEventListener(MouseEvent.CLICK, playVideoButton);
      stopBtn.addEventListener(MouseEvent.CLICK, stopVideoButton);
      volumeSlider.addEventListener( SliderEvent.CHANGE, volumeHandler );
      volumeSlider.addEventListener( SliderEvent.THUMB_RELEASE, flushVolumeSetting );

      mvMyVid.volume = 0;   //added by venkat for IR2372


      //var videoPath:String = this.loaderInfo.parameters["videoPath"];
      var playBtnFlag = this.loaderInfo.parameters["controls"];


      var videoPath = "rtmp://abc.org/abc/Production/1714fead26e0f42f0126e229ef210032/Diss.flv";


      var index = videoPath.indexOf("/production");
      if (index != -1){
        var strProduction = videoPath.slice(index, videoPath.length);
      }

      if (urlType == "Remote Media"){}
      else if (urlType == "Local Media"){

      videoPath = "http://localhost:8890" + strProduction;
      }
      else if (urlType == "Proctor"){
      videoPath = "http://" + ipAddress + ":8890" + strProduction;
      }

      if (playBtnFlag == undefined ){
      playBtnFlag = "none";
      }
      volumeSlider.value=volumeMedia*10;

       

      if (playBtnFlag == "none") {
      playBtn.visible = false;
      stopBtn.visible = false;
      volumeSlider.visible = false;
      }
      else if (playBtnFlag == "play") {
      playBtn.visible = true;
      stopBtn.visible = false;
      volumeSlider.visible = false;
      }
      else if (playBtnFlag == "playslider") {
      playBtn.visible = true;
      stopBtn.visible = false;
      volumeSlider.visible = true;
      }

      playBtn.stage.showDefaultContextMenu = false;
      volumeSlider.stage.showDefaultContextMenu = false;

      var skinPath = this.loaderInfo.parameters["skinPath"];
      var htmlId = this.loaderInfo.parameters["htmlId"];
      var loop = this.loaderInfo.parameters["loop"];
      var autoPlayPara = this.loaderInfo.parameters["play"];
      var playOnce = this.loaderInfo.parameters["playonce"];

      var videoCompleted:Boolean = false;

      //added event handler before the FLV is loaded by assigning value to source of 
      mvMyVid.addEventListener(VideoEvent.STATE_CHANGE, stateChangeHandler);


      mvMyVid.skin = skinPath;
      mvMyVid.bufferTime = bLengthMedia;
      mvMyVid.source = videoPath;

      if (skinPath == undefined){ //no skin
      mvMyVid.bufferingBar = bufferBar;
      }
      else { //there is skin passed in
      bufferBar.visible = false;
      }

      mvMyVid.stage.showDefaultContextMenu = false;
      mvMyVid.addEventListener(Event.COMPLETE, completeHandler);

      //**************************************
      //Uncomment the line below if you wish
      //  to set autorun=true in the debugger
      //playVideo();
      //**************************************
      playVideo();

      function initHandler(event:Event) {
      ExternalInterface.addCallback("playVideoContent", playVideo);
      ExternalInterface.addCallback("stopVideoContent", stopVideo);
      ExternalInterface.addCallback("pauseVideoContent", pauseVideo);
      ExternalInterface.addCallback("resumeVideoContent", resumeVideo);
      ExternalInterface.addCallback("isBufferingContent", isBuffering);
      //ExternalInterface.addCallback("playDoneContent", setPlayDone);
      ExternalInterface.addCallback("volumeUpVideoContent", volumeUp);
      ExternalInterface.addCallback("volumeDownVideoContent", volumeDown);

      //Javascript for INIT
      ExternalInterface.call("OnFlashInit", htmlId);

      }

      function stateChangeHandler(event:VideoEvent) {
       
      if (mvMyVid.state == "connectionError") {
        ExternalInterface.call("OnPlayError", "htmlId = " + htmlId + "_connectionError");
      }
      if (videoCompleted == false && mvMyVid.state == "disconnected") {
        ExternalInterface.call("OnPlayError", "htmlId = " + htmlId + "_disconnected");
      }
      if (videoCompleted == true && mvMyVid.state == "disconnected") {
        bufferBar.visible = false;
      }
      }

      function completeHandler(event:Event):void{
      //audio not in stimulus or voiceover or playBtnFlag undefined
      if (playBtnFlag == "play" ) {
        playBtn.visible = true;
        stopBtn.visible = false;
        volumeSlider.visible = false;
      }
      else if (playBtnFlag == "playslider") {
        playBtn.visible = true;
        stopBtn.visible = false;
        volumeSlider.visible = true;
      }
      //call OnPlayDone after first loop
      if (videoCompleted == false) {
        ExternalInterface.call("OnPlayDone", htmlId);
        if (playOnce=="true"&&mvMyVid.skin!=null) {
         mvMyVid.playButton = undefined;
        }
        if (playOnce=="true"&&playBtnFlag == "play") {
         playBtn.visible = false;
         stopBtn.visible = false;
         volumeSlider.visible = false;
        }
      }
      videoCompleted = true;
      //Handle (1) and (4)
      if (loop=="true") {
        if (playBtnFlag == "play") {
         playBtn.visible = false;
         stopBtn.visible = true;
         volumeSlider.visible = false;
        }
        mvMyVid.seek(0);
        //mvMyVid.play();
      }
      }

      function playVideoButton(event:MouseEvent):void{
      playVideo();
      }

      /*playVideo called when autoPlay=1/undefined
      autoPlay 1 1 1
      playOnce 0 1 0
      loop  1 0 0
         (1) (2) (3)
      if autoPlay=0, playVideo not called, use skin bar for user to play
      autoPlay 0 0 0
      playOnce 0 1 0
      loop  1 0 0
         (4) (5) (6)
      if loop=1, there could be skin bar or not, (1) and (4) (5)handled by completeHandler.
      there must be a skin control bar in (5)&(6)
      */
      function playVideo():void{

      mvMyVid.volume = volumeMedia; 
        //if it is not RTMP, handled by progress event
        if (mvMyVid.isRTMP) {
         // mvMyVid.play();
        }
       
      //handle (3) for http
      else {
        if (mvMyVid.bytesTotal == mvMyVid.bytesLoaded) {
         // mvMyVid.play();
        }
        else {
         mvMyVid.addEventListener(VideoProgressEvent.PROGRESS, httpDownloadHandler);
        }
      }

      //handle the buttons appear or disappear
      if (playBtnFlag == "none"){
        playBtn.visible = false;
        stopBtn.visible = false;
        volumeSlider.visible = false;
      }
      else if (playBtnFlag == "play"){
        playBtn.visible = false;
        stopBtn.visible = true;
        volumeSlider.visible = false;
      }
      else if (playBtnFlag == "playslider"){
        playBtn.visible = false;
        stopBtn.visible = true;
        volumeSlider.visible = true;
      }
      }

      function stopVideo():void {
      mvMyVid.autoRewind = true;
      mvMyVid.stop();

      //handle the buttons appear or disappear
      if (playBtnFlag == "none"){
        playBtn.visible = false;
        stopBtn.visible = false;
        volumeSlider.visible = false;
      }
      else if (playBtnFlag == "play"){
        playBtn.visible = true;
        stopBtn.visible = false;
        volumeSlider.visible = false;
      }
      else if (playBtnFlag == "playslider"){
        playBtn.visible = true;
        stopBtn.visible = false;
        volumeSlider.visible = true;
      }
      }

      function pauseVideo():void {
        mvMyVid.pause();
      }

      function resumeVideo():void {
      if (mvMyVid.paused == true) {
        // mvMyVid.play();
      }
      }

      function isBuffering():Boolean{
      return mvMyVid.state == VideoState.BUFFERING;
      }

      function httpDownloadHandler(event:VideoProgressEvent) {
      //if it is not RTMP, check if it is fully downloaded, if it is, then play video
      if (!mvMyVid.isRTMP && mvMyVid.bytesTotal == mvMyVid.bytesLoaded){
        // mvMyVid.play();
      }
      }

      function stopVideoButton (event:MouseEvent):void{
      stopVideo();
      }

      function volumeHandler(event:SliderEvent):void {
      mvMyVid.volume = event.value/10;  //make the voice range of the slider the same as the up and down function (0-1)
       
      }

      function flushVolumeSetting(event:SliderEvent):void {
      myLso.setProperty(VOLUME, event.value/10);
      myLso.flush();
      }


      function volumeUp():Number{
      //add 0.1 each time only if 0<volumeMedia<1
      if (volumeMedia < 0) {
        volumeMedia = 0;
      }
      else if (volumeMedia > 0.9){
        volumeMedia = 1;
      }
      else {
        volumeMedia += 0.1;
      }
      mvMyVid.volume = volumeMedia;
      myLso.setProperty(VOLUME, volumeMedia);
      myLso.flush();
      return volumeMedia;
      }

      function volumeDown():Number{
      //substract 0.1 each time only if the 0<volumeMedia<1
      if (volumeMedia < 0.1){
        volumeMedia = 0;
      }
      else if (volumeMedia > 1) {
        volumeMedia = 1;
      }
      else {
        volumeMedia -= 0.1;
      }

      mvMyVid.volume = volumeMedia;

      myLso.setProperty(VOLUME, volumeMedia);
      myLso.flush();
      return volumeMedia;
      }

       

      Please help me by giving your thoughts.