一旦用户尝试单击后退按钮或更改视图,我无法让此视图生成的视频流停止。有人可以帮我们弄清楚如何在退出的后退按钮上添加一个停止,以便在单击流时停止然后正确导航?
这是代码:
<?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>