2016-03-25 41 views
0

我想從AVAUDIOPLAYER的音頻流中檢索元數據(歌曲,藝術家)。我試着用這個代碼,但我沒有從多個URL獲得任何數據。使用AVAUDIOPLAYER從音頻流獲取元數據

NSURL *url = [NSURL URLWithString:urlString]; 
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil]; 
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init]; 

for (NSString *format in [asset availableMetadataFormats]) 

有人幫我嗎?也許我做錯了? AVAUDIOPLAYER可以做到這一點?

由於

+0

任何意見????? – Seb78

+0

我會使用'AVPlayer'而不是'AVAudioPlayer',然後您可以創建一個'AVPlayerItem'並將其與'AVPlayer'的一個實例相關聯。該項目的元數據可以通過使用其屬性(如「軌道」和「持續時間」)來檢索。 [這裏是文檔](https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayerItem_Class/index.html)。如果你想要'AVPlayerItem'不提供的附加元數據,那麼你可以先創建一個'AVAsset',並從該對象中檢索附加數據。然後您可以從AVAsset中創建一個AVPlayerItem' – MikeG

+0

感謝您的建議。任何解決方案與Avaudioplayer?也許它不可能獲得元數據.. ???? – Seb78

回答

0

下面是如何創建AVAsset並用它來創建,然後可以用AVPlayer實例相關聯的AVPlayerItem一個例子。元數據可以通過使用AVAsset屬性檢索...

var player = AVPlayer()  
func createAssetAndItem(){ 

    //create AVAsset from an NSURL. metadata can be retrieved from the asset depending on what is available 
let createdAVAsset = AVURLAsset(URL: songNSURL) 

    //create an AVPlayerItem from the AVAsset 
let createdAVItem = AVPlayerItem(asset: createdAVAsset) 

    //asscoaite AVPlayerItem with instance of AVPlayer 
player = AVPlayer(AVPlayerItem: createdAVItem) 


} 
+0

沒有工作:(我現在絕望,我沒有找到任何解決方案 – Seb78

+0

你現在在使用'AVPlayer'嗎?我們需要看你的代碼與你的嘗試有關,但你應該可以打開一個新的問題這也是你從哪裏得到的音頻文件?也許元數據不是推定的 – MikeG

+0

我回答,抱歉,我花了時間。 – Seb78