AVPlayer
odgrywa AVPlayerItem
. AVPlayerItem
s są wspierane przez obiekty klasy AVAsset
. Podczas korzystania z metody playerWithURL:
z AVPlayer
automatycznie tworzy ona AVPlayerItem
zabezpieczoną przez zasób będący podklasą AVAsset
o nazwie AVURLAsset
. AVURLAsset
ma właściwość URL
.
Tak, w przypadku, w którym podałeś, możesz łatwo uzyskać NSURL
aktualnie odtwarzanego przedmiotu. Oto przykładowa funkcja, jak to zrobić:
-(NSURL *)urlOfCurrentlyPlayingInPlayer:(AVPlayer *)player{
// get current asset
AVAsset *currentPlayerAsset = player.currentItem.asset;
// make sure the current asset is an AVURLAsset
if (![currentPlayerAsset isKindOfClass:AVURLAsset.class]) return nil;
// return the NSURL
return [(AVURLAsset *)currentPlayerAsset URL];
}
Nie jest szybkim ekspertem, ale wydaje się, że można to zrobić szybciej niż na krótko.
func urlOfCurrentlyPlayingInPlayer(player : AVPlayer) -> URL? {
return ((player.currentItem?.asset) as? AVURLAsset)?.url
}
The 'AVPlayer' [Dokumenty] (https://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVPlayer_Class/Reference/ Reference.html) nie wydają się dawać sposobu na pobranie adresu URL. Możesz spróbować sprawdzić, czy odpowiada on 'valueForKey:' z różnymi permutacjami '@" adresu URL "', ale wątpię, że zostanie ujawniony. – coneybeare