如何在iPhone上删除控件播放音乐时设置标题?

时间:2012-05-07 06:21:57

标签: iphone background-music

我正在制作一个广播应用,支持在后台播放音乐。但是我不知道如何设置音乐标题以取消控制。

我的应用与“音乐”之间的区别如下: Difference

我应该怎么做让我的应用程序显示像“音乐”这样的音乐的标题呢?

谢谢!

2 个答案:

答案 0 :(得分:6)

以下是示例代码:

#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];
    }
}

答案 1 :(得分:3)

您可以通过调用MPNowPlayingInfoCenter更改正在播放的标签的文本,这也可以让您在锁定屏幕上修改歌曲名称,专辑,艺术家和专辑封面。

#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];
    }
}

代码来自:jaysonlane.net