1 Reply Latest reply on Apr 3, 2013 6:33 AM by tanehesi

    How to stop or remove videostream from Flash Builder View

    tanehesi

      Greetings:

       

      I'm having problems getting the video stream generated by this view to stop once the user either attempts to click the back button or changes view.  Can someone help us figure how to add a stop to the exiting back button so that when clicked the stream stops and then navigates properly?

       

      Here's the code:

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark" viewDeactivate="view1_viewDeactivateHandler(event)" initialize="view1_initializeHandler(event)" backgroundColor="#000000" title="{data.title}">

      <fx:Script>
        <![CDATA[
         import mx.core.mx_internal;
         import mx.events.FlexEvent;
        
         import spark.events.ViewNavigatorEvent;
         protected function liveStream_completeHandler(event:Event):void
         {
          // TODO Auto-generated method stub
          if(!this.parentApplication.isTablet) theGroup.horizontalScrollPosition = liveStream.width / 2;
         
          bi.visible = false;
         }
        
         protected function view1_initializeHandler(event:FlexEvent):void
         {
          // TODO Auto-generated method stub
          systemManager.stage.addEventListener(KeyboardEvent.KEY_DOWN, deviceKeyDownHandler);
          systemManager.stage.addEventListener(KeyboardEvent.KEY_UP, deviceKeyUpHandler);
         }
        
         protected function deviceKeyDownHandler(event:KeyboardEvent):void
         {
          // TODO Auto-generated method stub
          if(event.keyCode == Keyboard.BACK && navigator.length > 1){
           event.preventDefault();
           this.liveStream.source = null;
           this.liveStream.source = VideoPlayer;
          }
         }
        
         protected function deviceKeyUpHandler(event:KeyboardEvent):void
         {
          // TODO Auto-generated method stub
          if(event.keyCode == Keyboard.BACK && navigator.length > 1){
           navigator.popView();
          }
         }
        
         protected function view1_viewDeactivateHandler(event:ViewNavigatorEvent):void
         {
          // TODO Auto-generated method stub
          systemManager.stage.removeEventListener(KeyboardEvent.KEY_DOWN, deviceKeyDownHandler);
          systemManager.stage.removeEventListener(KeyboardEvent.KEY_UP, deviceKeyUpHandler);
         }
        
        ]]>
      </fx:Script>

      <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
      </fx:Declarations>
      <s:navigationContent>
        <s:Button label="Back" visible="{!this.parentApplication.isTablet}"
            click="navigator.popView()"/>
      </s:navigationContent>

      <s:Scroller width="100%" height="100%" id="streamScroller">
        <s:Group id="theGroup">
         <s:VideoPlayer width="100%" height="100%" complete="liveStream_completeHandler(event)" source="some_source/livestream.f4m" maintainProjectionCenter="true" scaleMode="zoom" id="liveStream"/>
        </s:Group>
      </s:Scroller>
      <s:BusyIndicator id="bi" width="40" height="40"  horizontalCenter="0" verticalCenter="0"/>
      </s:View>