【问题标题】:Best Way To Display Music Play Controls On Lock Screen iOS7 [duplicate]在锁定屏幕iOS7上显示音乐播放控件的最佳方式[重复]
【发布时间】:2014-02-24 19:16:35
【问题描述】:

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

非常感谢!

【问题讨论】:

    标签: ios iphone ios7 lockscreen audio-player


    【解决方案1】:

    非常有用的指南 - 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];
        }
    }
    

    下次尝试使用搜索:

    【讨论】:

    • 问题已经被标记为重复,除了从问题中提取代码之外,我还添加了非常有用的教程以及对以下代码的解释......
    猜你喜欢
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多