如何将AVPlayer Current Item与MPMediaItem进行比较?

时间:2011-09-07 06:40:49

标签: avplayer mpmediaitem

我正在实施一个基于音频的应用程序。我正在使用AVPlayer播放从iPod库中选择的MPMedia项目列表。在我的应用程序中,我需要测试1个案例,即我需要将当前播放(来自AVPlayer)与MPMedia项目列表进行比较。我怎么能这样做?

为了便于理解,我需要以下内容:

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

        printf("Do some action");
    }
}

1 个答案:

答案 0 :(得分: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");
}