如何在iPhone上播放音乐在后台时设置的标题? [英] How to set the title when playing music in background on iPhone?

查看:508
本文介绍了如何在iPhone上播放音乐在后台时设置的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在一个电台的应用程序,它支持播放音乐的背景。但我得到停留在如何设置音乐的标题去掉控制。

I'm working on a radio app, which supports playing music in background. But i get stuck in how to set the title of music to remove control.

在遥控器,我的应用程序看起来像这样(RadioTaste是我的应用程序的名称):

In remote control, my app looks like this(RadioTaste is my app's name):


和苹果的音乐应用程序是这样的:

And Apple's "Music" app looks like this:


我应该怎么做,使我的应用程序显示一个类似乐吗?

What i should do to make my app display the title of a music like "Music" do?

谢谢!

推荐答案

完全一样的评论,这里的例子code:

exactly as in the comment , here's the example code :

#import <MediaPlayer/MPNowPlayingInfoCenter.h>
#import <MediaPlayer/MPMediaItem.h>

MPMediaItemArtwork *albumArt;


- (void)changeTrackTitles
{
  Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

    if (playingInfoCenter) 
    {
        albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imageNamed:@"HexagonArtwork"]];
        NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
        [songInfo setObject:@"SongName" forKey:MPMediaItemPropertyTitle];
        [songInfo setObject:@"AlbumName" forKey:MPMediaItemPropertyAlbumTitle];
        [songInfo setObject:@"ArtistName" forKey:MPMediaItemPropertyArtist];
        [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
    }
}

我希望这将有助于..

i hope this will help..

这篇关于如何在iPhone上播放音乐在后台时设置的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆