This question already has answers here:
Changing iphone lock screen programmatically when app is running in background

(2个答案)


6年前关闭。




我有一个音乐应用。使歌曲信息和音乐控件显示在诸如SoundCloud之类的锁定屏幕中的最佳方法是什么-请参阅(http://cl.ly/image/1a1H041A1Z34)

非常感谢你!

最佳答案

非常有用的指南-Lock screen “Now Playing” with MPNowPlayingInfoCenter;

这仅适用于iOS 5+,并且已完成类似操作。

- (void)setupNowPlayingInfoCenter:(MPMediaItem *)currentSong
{
    NSString *ver = [[UIDevice currentDevice] systemVersion];
    CGFloat version = 4.0;
    if ([ver length] >= 3)
    {
        version = [[ver substringToIndex:3] floatValue];
    }

    if (version >= 5.0)
    {
        MPMediaItemArtwork *artwork = [currentSong valueForProperty:MPMediaItemPropertyArtwork];

        MPNowPlayingInfoCenter *infoCenter = [MPNowPlayingInfoCenter defaultCenter];

        if (currentSong == nil)
        {
            infoCenter.nowPlayingInfo = nil;
            return;
        }

        infoCenter.nowPlayingInfo = [NSDictionary dictionaryWithObjectsAndKeys:
                [currentSong valueForKey:MPMediaItemPropertyTitle], MPMediaItemPropertyTitle,
                [currentSong valueForKey:MPMediaItemPropertyArtist], MPMediaItemPropertyArtist,
                [currentSong valueForKey:MPMediaItemPropertyAlbumTitle], MPMediaItemPropertyAlbumTitle,
                [currentSong valueForKey:MPMediaItemPropertyAlbumTrackCount], MPMediaItemPropertyAlbumTrackCount,
                [currentSong valueForKey:MPMediaItemPropertyAlbumTrackNumber], MPMediaItemPropertyAlbumTrackNumber,
                artwork, MPMediaItemPropertyArtwork,
                [currentSong valueForKey:MPMediaItemPropertyComposer], MPMediaItemPropertyComposer,
                [currentSong valueForKey:MPMediaItemPropertyDiscCount], MPMediaItemPropertyDiscCount,
                [currentSong valueForKey:MPMediaItemPropertyDiscNumber], MPMediaItemPropertyDiscNumber,
                [currentSong valueForKey:MPMediaItemPropertyGenre], MPMediaItemPropertyGenre,
                [currentSong valueForKey:MPMediaItemPropertyPersistentID], MPMediaItemPropertyPersistentID,
                [currentSong valueForKey:MPMediaItemPropertyPlaybackDuration], MPMediaItemPropertyPlaybackDuration,
                [NSNumber numberWithInt:self.mediaCollection.nowPlayingIndex + 1], MPNowPlayingInfoPropertyPlaybackQueueIndex,
                [NSNumber numberWithInt:[self.mediaCollection count]], MPNowPlayingInfoPropertyPlaybackQueueCount, nil];
    }
}

下次,尝试使用搜索:
  • Changing iphone lock screen programmatically when app is running in background
  • 关于ios - 在锁屏iOS7上显示音乐播放控件的最佳方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21996861/

    10-14 21:39