2014-03-06 63 views
4

我有一個應用程序正在Kiosk上運行,打開全天循環視頻。最終,大約1天后,應用程序凍結。視頻循環凍結了我的iOS應用程序

這裏是14小時的運行後的儀器會話: enter image description here enter image description here enter image description here enter image description here

我不是很熟悉儀器着呢,雖然現場字節保持一致,併爲低,其他數值似乎非常高。但是,我不確定這是否正常。

這是我如何創建視頻播放器:

- (void)setupInitialContentWithBounds:(CGRect)externalScreenBounds 
{ 
    avPlayer = [[AVPlayer alloc] init]; 
    avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer]; 
    avPlayerLayer.frame = externalScreenBounds; 
    [self.externalWindow.layer addSublayer:avPlayerLayer]; 
    avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(playerItemDidReachEnd:) 
               name:AVPlayerItemDidPlayToEndTimeNotification 
               object:[avPlayer currentItem]]; 

    [self playVideo:@"Idle"]; 
} 

這裏是的playVideo方法:

- (void)playVideo:(NSString *)name 
{ 
    currentVideo = name; 
    NSString *filepath = [[NSBundle mainBundle] pathForResource:name ofType:@"mp4"]; 
    NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 
    AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:fileURL]; 
    [avPlayer replaceCurrentItemWithPlayerItem:playerItem]; 
    [avPlayer play]; 
} 

這裏的視頻結束後通知偵聽器:

- (void)playerItemDidReachEnd:(NSNotification *)notification 
{ 
    if([currentVideo isEqualToString:@"Idle"]) 
    { 
     //Keeps looping the Idle video until another one is selected 
     AVPlayerItem *p = [notification object]; 
     [p seekToTime:kCMTimeZero]; 
    } 

    else 
    { 
     NSLog(@"Just finished a different video, so go back to idle"); 
     [self playVideo:@"Idle"]; 
    } 
} 

編輯:起初我的客戶告訴我它墜毀,但它看起來像它實際上凍結,視頻停止p鋪設和應用程序沒有反應。有任何想法嗎?

+0

你有一個崩潰報告,告訴你,這是由於內存壓力?併爲這個愚蠢的問題表示歉意,但這個信息亭肯定會在一天之內收取費用。 – davbryn

+0

不幸的是我沒有,因爲它發生在位置上。我無法複製它,因爲視頻正在通過輔助屏幕,如果我連接了該屏幕,則無法將設備連接到Xcode。儀器在模擬器上運行,儘管它沒有崩潰,但是當我在14小時後嘗試使用它時,該應用程序非常反應遲鈍。 – Jan

+0

您的應用程序是否監視可用磁盤空間? – bneely

回答

0

我從來沒有使用過AVPlayer類,但我們有一個無限循環的視頻應用類似的場景爲展覽

總體而言,它看起來像你的應用程序得到一些內存,如果運行了很長一段時間。也許AVPlayer會導致一些內存泄漏?

  • 在視頻結束事件:釋放你的播放器(設置爲nil)並重新初始化它(如在啓動時),而不是循環的。如果一些「垃圾」應該落後,ARC可能會做休息...

    //release your player (taken from here: http://stackoverflow.com/questions/17831764/how-to-stop-a-video-in-avplayer) 
    [self.videoPlayer Pause]; 
    [self.avPlayerLayer removefromsuperlayer]; 
    self.videoPlayer = nil; 
    
    //re-init 
    
  • 確保您setupInitialContentWithBounds只調用一次,否則你可能會調用addObserver幾次,可導致奇怪的副作用(或你在某些時候調用removeObserver

1

我不能回答你關於崩潰的問題,只是確認,我們已經看到在這裏類似的崩潰,可能是同樣的問題。

但我可以幫助您更好地解釋儀器的顯示。我不會擔心Overall Bytes# Overall的值非常高。這些衡量自應用程序啓動以來(或自儀器附加以來)分配的總內存量。也就是說,分配1MB然後釋放它將增加1MB到這些總數。

我期望的Overall Bytes量是size of video * play count或多或少比例。