2011-07-19 37 views
0

我正在開發用於iPad的應用程序(使用Titanium Appcelerator),用於記錄和播放多個視頻文件。此時,我可以無休止地錄製視頻,但當我播放它們時,應用程序會隨機崩潰。例如:播放視頻A,然後播放視頻B,然後播放C,然後返回到A,並在回放過程中應用程序回到主屏幕。重新啓動應用程序並執行完全相同的操作,這樣會很好,並讓我再播放另外幾個視頻,然後當我回到視頻列表時再崩潰。在崩潰日誌往往開始與此:iPad 2視頻子系統不穩定?

Exception Type: EXC_BAD_ACCESS (SIGSEGV) 
Exception Codes: KERN_INVALID_ADDRESS at 0x4650974c 
Crashed Thread: 0 

Thread 0 name: Dispatch queue: com.apple.main-thread 
Thread 0 Crashed: 
0 libobjc.A.dylib     0x33adbca4 0x33ad9000 + 11428 
1 MediaPlayer      0x354469d6 0x353d9000 + 448982 
2 Foundation      0x333dd7c6 0x3334d000 + 591814 
3 CoreFoundation     0x3712ea40 0x370b9000 + 481856 
4 CoreFoundation     0x37130ec4 0x370b9000 + 491204 
5 CoreFoundation     0x3713183e 0x370b9000 + 493630 
6 CoreFoundation     0x370c1ebc 0x370b9000 + 36540 
7 CoreFoundation     0x370c1dc4 0x370b9000 + 36292 
8 GraphicsServices    0x36ffc418 0x36ff8000 + 17432 
9 GraphicsServices    0x36ffc4c4 0x36ff8000 + 17604 
10 UIKit       0x35009d62 0x34fdb000 + 191842 
11 UIKit       0x35007800 0x34fdb000 + 182272 
12 VideoRiver      0x000042bc 0x1000 + 12988 
13 VideoRiver      0x00003b60 0x1000 + 11104 
  • 的iOS SDK 4.3,
  • 的XCode 3.2.6,
  • 鈦SDK 1.7.1,
  • iPad 2的32GB 3G,
  • iPad的iOS 4.3.3
+1

如果您希望人們提供幫助,您應該回頭接受以前問題的答案。 :) ..就你的問題而言,這聽起來像是內存泄漏。確保你沒有保留你不再需要的視頻數據。 –

+0

謝謝,傑西,我會那樣做的。 據我所知,我正在做可以做的事情,即停止視頻並在完成後調用.release()方法: myVideo.stop(); myVideo.release(); – mpemburn

回答

0

我相信我找到了解決方法。到目前爲止,在我的問題中概述的相同情況下沒有崩潰。不同之處在於,不是爲視頻創建單獨的窗口,而是將視頻播放器放在視圖上,然後根據需要隱藏和顯示視頻。下面是鈦Appcelerator的一些代碼,工作原理:

function Playback() { 

    var self = this; 
    this.activeMovie = null; 
    this.baseView = null; 

    this.create = function() { 

     self.activeMovie = Ti.Media.createVideoPlayer({ 
      top: 0, 
      left: 0, 
      width: Ti.Platform.displayCaps.platformWidth, 
      height: Ti.Platform.displayCaps.platformHeight, 
      backgroundColor: '#111', 
      movieControlStyle: Ti.Media.VIDEO_CONTROL_EMBEDDED, 
      scalingMode: Ti.Media.VIDEO_SCALING_ASPECT_FIT 
     }); 

     self.baseView = Ti.UI.createView({ 
      top: 0, 
      left: 0, 
      width: Ti.Platform.displayCaps.platformWidth, 
      height: Ti.Platform.displayCaps.platformHeight 
     }); 

     self.baseView.hide(); 

     self.doneBtn = Ti.UI.createButton({ 
      title: 'Done', 
      color: '#fff', 
      backgroundColor: 'blue', 
      backgroundImage: 'none', 
      bottom: '15%', 
      width: 120, 
      height: 40, 
      font: {fontSize: 16,fontWeight: 'bold',fontFamily: 'Helvetica Neue'}, 
      borderRadius:5, 
      borderWidth:1, 
      borderColor:'#a6a6a6' 
     }); 

     self.doneBtn.addEventListener('click', function() { 
      self.hide(); 
     }); 

     self.activeMovie.addEventListener('playbackState', function (e) { 
      //*** Hide the video window when done. Comment out if you don't want to do this. 
      if (e.playbackState == 0) { 
       self.hide(); 
      } 
     }); 

     self.baseView.add(self.activeMovie); 
     self.baseView.add(self.doneBtn); 

    }; 

    Playback.prototype.getView = function() { 
     return self.baseView; 
    }; 

    Playback.prototype.show = function (filename) { 
     self.activeMovie.url = Titanium.Filesystem.applicationDataDirectory + '/' + filename; 
     self.baseView.show(); 
     self.activeMovie.play(); 
    }; 

    Playback.prototype.hide = function() { 
     self.baseView.hide(); 
     self.activeMovie.stop(); 
    }; 

    this.create(); 
} 

要使用此功能,請執行下列操作:

var player = new Playback(); 
Titanium.UI.currentWindow.add(player.getView()); 
player.show("mymovie.mov"); 

享受!

+0

應該加上: 'this.doneBtn = null;' 來聲明它保持整潔。 – mpemburn