【问题标题】:How to compare AVPlayer Cureent Item with MPMedia Item?如何比较 AVPlayer Current Item 和 MPMediaItem?
【发布时间】:2011-09-07 06:40:49
【问题描述】:

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

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

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

        printf("Do some action");
    }
}

【问题讨论】:

  • 我用下面的代码试过了,但是没成功,MPMediaItem anItem=[songs objectAtIndex:index]; NSURL *itemURL = [anItem valueForProperty:MPMediaItemPropertyAssetURL];AVAsset assets = [[AVURLAsset alloc] initWithURL:itemURL options:nil];NSString * trackingKey = @"tracks";[asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler:^{AVPlayerItem* item=[AVPlayerItem playerItemWithURL:itemURL];AVPlayerItem* nextPlayItem = [AVPlayerItem playerItemWithAsset:asset]; if(nextPlayItem==[appDelegate.avPlayer currentItem]) { } }];

标签: avplayer mpmediaitem


【解决方案1】:
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");
}

【讨论】:

    猜你喜欢
    • 2021-10-08
    • 2021-09-19
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    • 2019-01-22
    • 1970-01-01
    • 2013-11-20
    • 2017-10-08
    相关资源
    最近更新 更多