2012-09-02 31 views
1

當我通過stage.stageVideos [0]實例化一個新的StageVideo insta時,一切都很好,但是當我離開我的視圖時,它將顯示它在舞臺上的視頻。所以當我轉到另一個視角時,它仍然在背景舞臺上顯示。我試着設置sv = null,刪除事件監聽器等等。 我創建它在MXML像實例化的StageVideoDisplay類:和視圖初始化我所說的play()方法:Flex Mobile 4.6 StageVideo不會從舞臺上移除

if (_path) 
     { 
      //... 
      // Connections 
      _nc = new NetConnection(); 
      _nc.connect(null); 
      _ns = new NetStream(_nc); 
      _ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); 
      _ns.client = this; 

      // Screen 
      _video = new Video(); 
      _video.smoothing = true; 

      // Video Events 
      // the StageVideoEvent.STAGE_VIDEO_STATE informs you whether 
      // StageVideo is available 
      stage.addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, 
       onStageVideoState); 
      // in case of fallback to Video, listen to the VideoEvent.RENDER_STATE 
      // event to handle resize properly and know about the acceleration mode running 
      _video.addEventListener(VideoEvent.RENDER_STATE, videoStateChange); 
      //... 
     } 

在視頻舞臺活動:

if (stageVideoInUse) { 
      try { 
       _rc = new Rectangle(0,0,this.width,this.height); 
       _sv.viewPort = _rc;  
      } catch (e:Error) {} 
     } else { 
      try { 
       _video.width = this.width; 
       _video.height = this.height; 
      } catch (e:Error) {} 
     } 

在舞臺上的視頻可用性事件:

protected function toggleStageVideo(on:Boolean):void 
    {  
     // To choose StageVideo attach the NetStream to StageVideo 
     if (on) 
     { 
      stageVideoInUse = true; 
      if (_sv == null) 
      { 
       try { 
        _sv = stage.stageVideos[0]; 
        _sv.addEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange); 
        _sv.attachNetStream(_ns); 
        _sv.depth = 1; 
       } catch (e:Error) {} 
      } 

      if (classicVideoInUse) 
      { 
       // If you use StageVideo, remove from the display list the 
       // Video object to avoid covering the StageVideo object 
       // (which is always in the background) 
       stage.removeChild (_video); 
       classicVideoInUse = false; 
      } 
     } else 
     { 
      // Otherwise attach it to a Video object 
      if (stageVideoInUse) 
       stageVideoInUse = false; 
      classicVideoInUse = true; 
      try { 
       _video.attachNetStream(_ns); 
       stage.addChildAt(_video, 0); 
      } catch (e:Error) {} 
     } 

     if (!played) 
     { 
      played = true; 
      _ns.play(path); 
     } 
    } 

會發生什麼事是在視圖中時,我navigator.popView()中的StageVideo仍然在舞臺上,甚至在其他視圖,並返回到何時該觀點發揮不同的流,同一個流是一種「燒」在上面。我無法想出擺脫它的辦法!提前致謝!

回答

2

在Flash Player 11中,Adobe將dispose()方法添加到NetStream類中。

當您完成此操作時,清除VideoStageVideo對象時非常有用。

當您在運行時調用dispose()方法時,可能會得到一個異常,指出NetStream對象上沒有名爲dispose的屬性。

發生這種情況是因爲Flash Builder未使用正確的SWF版本編譯應用程序。爲了解決這個問題,只需添加到您的編譯器指令:

-swf-version=13

在新的Flash Builder的4.7,我們希望不會有指定的SWF版本使用新的Flash Player功能。

這似乎是最好的解決辦法,但如果你不能使用Flash 11(或最新版本的Adobe AIR),其他一些變通是:

  • 設置舞臺視頻對象的viewPort到有寬度= 0和高度= 0
  • 因爲舞臺視頻出現在你的應用程序下方的矩形,你總是可以覆蓋視口(帶有背景色或一些DisplayObject
+0

謝謝。不幸的是,這似乎沒有做任何事情。它似乎有助於視頻在離開視圖時不在背景中播放。然而,stageVideo仍然出現在舞臺上時,轉向另一種觀點。另外,當移動到相同的視圖,並試圖播放另一個視頻時,同一個視頻仍然處於暫停狀態或剛剛位於頂部的某個位置... – Michael

+0

適用於網絡上的我,我從未嘗試過w /空氣。這是發生在設備和模擬器上嗎?看到更多的代碼或者你正在做什麼的簡單例子可能會有幫助。請記住,舞臺視頻位於您的應用下方,因此作爲最後一招,您可以隱藏它。 –

+0

你好,是的,它在AIR 3.3(最新版本)和Android設備上。我基本上遵循了教程,並創建了一個StageVideoDisplay類,它具有一個play()方法,可以實現簡單的網絡連接和網絡流對象。之後,我只是檢查可用性,並使用視頻對象或stage.stageVideos [0]對象。當我點擊後退按鈕時,我嘗試將所有內容全部刪除並刪除監聽器,但這似乎並沒有做任何事情。在視圖初始化我調用在mxml <組件中實例化類的play()函數:StageVideoDisplay /> – Michael

0

好這個問題實際上是,即使它看起來像st因爲我收到了狀態爲「加速」的信息,實際上視頻渲染器甚至在運行,而經典視頻實際上正在使用中。我需要做的唯一事情就是將stage.removeChild(_video)添加到類中的close()事件中!