3
在這裏,我曾經使用AVAudioPlayer Framework
播放歌曲。但願這是玩,但如果我在其他歌曲點擊來自Songslist我將檢查條件:如何從AVAudioPlayer發佈NSDATA?
if(player.isPlaying == YES)
{
[player stop];
// And also i need to release or remove the existing NSDATA from the Player. otherwise the player won't release the existing data. So the memory pressure occurring in my project.
}
self.audioPlayer = [self.audioPlayer initWithData:m_currentMusic.fileData error:&error];
[self.audioPlayer prepareToPlay];
[self.audioPlayer play];
看到這裏我不想再創造再與ALLOC。因爲玩家只創建一次。我想替換nsdata。我也用[self.audioplayer stop]; [self.audioplayer release] ;.如果我再點擊一首歌曲,「編譯器告訴BAD ACCESS」,此代碼再次適用於不同的歌曲。 – iTag
'[self.audioPlayer發佈]'釋放你的'AVAudioPlayer'。之後它就無法使用了,因爲在某些時候內存將會被回收(所以你不能在這個時候播放曲目或者出現各種各樣的錯誤)。不幸的是,由於AVAudioPlayer#data屬性標記爲readonly(無法設置),因此無法重置數據。請參閱[AVAudioPlayer類參考](https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Chapters/Reference.html#//apple_ref/occ/instp/AVAudioPlayer/data)。你必須重置你的播放器。 – wmorrison365
不良訪問=您釋放了內存,但仍在使用播放器(如您在評論中所述)。也許還可以看看[這個Cocoa內存管理指南](https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/MemoryManagement.html)(注意它是Cocoa)。 – wmorrison365