Ios 如何在控制中心显示寻道轨迹持续时间

Ios 如何在控制中心显示寻道轨迹持续时间,ios,objective-c,avaudioplayer,avaudiosession,control-center,Ios,Objective C,Avaudioplayer,Avaudiosession,Control Center,如何将歌曲信息(如歌曲名称和曲目持续时间)传递到控制中心。 播放器可以很好地播放音乐,播放和暂停控制也可以很好地工作 玩苹果的音乐应用程序 使用下面的代码玩我的应用程序,如何传递歌曲信息以显示它 不确定,但这段代码可能会对您有所帮助 - (void) handle_NowPlayingItemChanged: (id) notification { MPMediaItem *currentItem = [musicPlayer nowPlayingItem]; NS

如何将歌曲信息(如歌曲名称和曲目持续时间)传递到控制中心。 播放器可以很好地播放音乐,播放和暂停控制也可以很好地工作

玩苹果的音乐应用程序

使用下面的代码玩我的应用程序,如何传递歌曲信息以显示它


不确定,但这段代码可能会对您有所帮助

   - (void) handle_NowPlayingItemChanged: (id) notification
{
    MPMediaItem *currentItem = [musicPlayer nowPlayingItem];
    NSString *titleString = [currentItem valueForProperty:MPMediaItemPropertyTitle];
    if (titleString)
    {
        titleLabel.text = [NSString stringWithFormat:@"Title: %@",titleString];
    } 
    else 
    {
        titleLabel.text = @"Title: Unknown title";
    }
}

我今天碰巧在做同样的事情,不知道答案,但在我的应用程序中,控制中心确实显示了应用程序名称。我想展示我正在玩的东西的标题。我甚至有一张我想展示的照片,比如专辑封面。我不认为我做了什么不同于你,我没有任何代码发送它的应用程序名,例如


等一下。。。我看到有一个叫做MPNowPlayingFoCenter的东西,我们应该看看。

你在播放iPod音乐库中的歌曲吗? 如果选择“是”,则MPMusicLayerViewController将为搜索栏属性和信息中心提供内置功能

我可以在你的代码中看到你使用了AVAudioPlayer, 我们只能使用AVAudioPlayer类设置以下详细信息,但无法在我们的应用程序中访问seekbar更改事件

NSMutableDictionary *albumInfo = [[NSMutableDictionary alloc] init];
UIImage *artWork = [UIImage imageNamed:album.imageUrl];
[albumInfo setObject:album.title forKey:MPMediaItemPropertyTitle];
[albumInfo setObject:album.auther forKey:MPMediaItemPropertyArtist];
[albumInfo setObject:album.title forKey:MPMediaItemPropertyAlbumTitle];
[albumInfo setObject:artworkP forKey:MPMediaItemPropertyArtwork];
[albumInfo setObject:album.playrDur forKey:MPMediaItemPropertyPlaybackDuration]
[albumInfo setObject:album.elapsedTime forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime]
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:albumInfo]

在这里,我们需要按所需格式计算album.playrDur和album.elapsedTime。

您要查找的是:

- (IBAction)playButtonTouched:(id)sender {

   Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

    if (playingInfoCenter) {


        NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];


        MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imagedNamed:@"AlbumArt"]];

        [songInfo setObject:@"Audio Title" forKey:MPMediaItemPropertyTitle];
        [songInfo setObject:@"Audio Author" forKey:MPMediaItemPropertyArtist];
        [songInfo setObject:@"Audio Album" forKey:MPMediaItemPropertyAlbumTitle];
        [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];


    }
}

用截图编辑检查这个很棒的答案:嗨@iMove,谢谢你的回复,但这不是我想要的。用屏幕快照Shi lepton更新了我的问题,我用我想要的更新了我的问题,发现我找不到曲目…..当我调用advanceToNextItem时,音频细节不会显示在锁屏上。@ABJ没有得到你,什么是advanceToNextItem?你是说“>>”下一首歌按钮吗?如果是,那么它将调用一个委托方法,从那里您再次需要更新下一首歌的信息,如上面所述。
- (IBAction)playButtonTouched:(id)sender {

   Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

    if (playingInfoCenter) {


        NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];


        MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imagedNamed:@"AlbumArt"]];

        [songInfo setObject:@"Audio Title" forKey:MPMediaItemPropertyTitle];
        [songInfo setObject:@"Audio Author" forKey:MPMediaItemPropertyArtist];
        [songInfo setObject:@"Audio Album" forKey:MPMediaItemPropertyAlbumTitle];
        [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];


    }
}