在iPhone上使用删除控制播放音乐时如何设置标题? [英] How to set the title when playing music with remove control on iPhone?

查看:62
本文介绍了在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.

我的应用程序和音乐"之间的区别如下:

The difference between my app and "Music" is as following:

我应该怎么做才能使我的应用显示音乐"之类的音乐的标题?

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

谢谢!

推荐答案

您可以通过调用MPNowPlayingInfoCenter更改正在播放的标签的文本,这还允许您修改歌曲名称,专辑,艺术家和专辑插图在锁定屏幕上.

You can change the text of the now playing label by calling the MPNowPlayingInfoCenter, this will also allow you to modify the song name, album, artist, and album artwork on the lock screen.

#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

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

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