2011-09-07 72 views
0

我正在实现一个基于音频的应用程序。我正在使用AVPlayer播放从iPod库中选择的MPMedia项目列表。在我的应用程序中,我需要测试1个案例,那就是我需要将当前正在播放的(来自AVPlayer)与MPMedia项目列表进行比较。我怎样才能做到这一点?为了便于理解,以下是我需要的,如何比较AVPlayer Cureent物品和MPMedia物品?

for(MPMediaItems) 
{ 
    if([MPmedia Item]== [AVPlayer CurrentItem]) 
    { 

     printf("Do some action"); 
    } 
} 

你们能帮我解决吗?这对我来说非常紧迫。

由于提前, Sekhar

+0

我用下面的代码试过,但不能成功,MPMediaItem * anItem = [歌曲objectAtIndex:指数]; NSURL * itemURL = [anItem valueForProperty:MPMediaItemPropertyAssetURL]; AVAsset * asset = [[AVURLAsset alloc] initWithURL:itemURL options:nil]; NSString * tracksKey = @“tracks”; [asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler:^ {AVPlayerItem * item = [AVPlayerItem playerItemWithURL:itemURL]; AVPlayerItem * nextPlayItem = [AVPlayerItem playerItemWithAsset:asset]; if(nextPlayItem == [appDelegate.avPlayer currentItem]) { } }]; – ChandraSekhar

回答

3
MPMediaItem *song; 
NSURL *songURL = [song valueForProperty: MPMediaItemPropertyAssetURL]; 
AVURLAsset *asset1 = (AVURLAsset *)[_avPlayer.currentItem asset]; //currentItem is AVAsset type so incompitable pointer types ... notification will occur, however it does contain URL (see with NSLog) 
AVURLAsset *asset2 = [AVURLAsset URLAssetWithURL: songURL options: nil]; 
if ([asset1.URL isEqual: asset2.URL]) { 
    printf("Do some action"); 
}