标签: mpnowplayinginfocenter

是否有公共方法强制MPNowPlayingInfoCenter显示播客控件?

我希望控制中心(通过MPNowPlayingInfoCenter)显示Apple用播客显示的前进15秒/后15秒控制,如下所示:

播客控件

完全缺乏文档告诉我,没有明显的方法可以做到这一点,但有没有人发现任何非显而易见的方法来强制这个而不诉诸私有方法?

我已经处理了前进/后退按钮设置以适当推进,我只想使用更合适的UI.任何帮助将不胜感激.

audio ios mpnowplayinginfocenter ios7 control-center

50
推荐指数
2
解决办法
1万
查看次数

暂停播放时,MPNowPlayingInfoCenter无法正常响应

我正在尝试让MPNowPlayingInfoCenter在暂停播放时正常工作.(我有一个使用AVPlayer播放的流媒体音乐应用程序,我正在通过Airplay播放我的Apple TV.)除了暂停之外的所有内容似乎都在Apple TV UI中正确反映出来.我正在初始化它像这样:

MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
NSDictionary *songInfo = @{
    MPMediaItemPropertyTitle: title,
    MPMediaItemPropertyArtist: artist
};
center.nowPlayingInfo = songInfo;
Run Code Online (Sandbox Code Playgroud)

由于我正在播放,因此在开始播放时我没有持续时间信息.当我从流中获得"就绪"信号时,我会更新Apple TV上正确显示的持续时间:

MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
NSMutableDictionary *playingInfo = [NSMutableDictionary dictionaryWithDictionary:center.nowPlayingInfo];
[playingInfo setObject:[NSNumber numberWithFloat:length] forKey:MPMediaItemPropertyPlaybackDuration];
center.nowPlayingInfo = playingInfo;
Run Code Online (Sandbox Code Playgroud)

当用户寻找音轨时,我也可以使用这种技术:

[playingInfo setObject:[NSNumber numberWithFloat:length * targetProgress] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚的一件事是,如何暂停Apple TV上的播放头.当用户在我的UI中点击暂停时,我正在尝试执行以下操作:

MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
NSMutableDictionary *playingInfo = [NSMutableDictionary dictionaryWithDictionary:center.nowPlayingInfo];        
[playingInfo setObject:[NSNumber numberWithFloat:0.0f] forKey:MPNowPlayingInfoPropertyPlaybackRate];            
center.nowPlayingInfo = playingInfo;
Run Code Online (Sandbox Code Playgroud)

这不是暂停,而是将播放头追回到零并继续前进.

如何让播放头在Apple TV UI中正确暂停?

ios avplayer airplay mpnowplayinginfocenter

45
推荐指数
2
解决办法
1万
查看次数

MPNowPlayingInfoCenter在音频流停止时消失

我的应用程序播放流式音频AVPlayer,并用于MPNowPlayingInfoCenter在设备锁定屏幕上显示有关流的信息.

这在音频实际播放时工作正常,但如果流因网络减速(即我收到AVPlayerItemPlaybackStalledNotification)而停止,则信息会从锁定屏幕消失.但是如果流恢复播放,它会重新出现.

这是令人困惑的,因为当现在播放的信息从锁定屏幕消失时,它给出了应用程序已停止播放的外观.但是当锁定屏幕UI似乎表明这不会发生时,它会恢复播放.

有什么我可以做的事情来确保现在播放的信息在流应该播放时仍然可见,但目前不是由于网络速度问题?似乎保持一致的锁屏UI的唯一方法是在网络连接停止时实际终止它,这有点愚蠢但至少不会混淆.

如果更多细节会有所帮助:

  • 当应用程序获得该通知时,它唯一做的就是更新UI.
  • MPNowPlayingInfoCenter当有一个当前程序时,应用程序永远不会清除,因此只要该流应该正在播放,就应该显示非空数据.

audio avfoundation ios avplayer mpnowplayinginfocenter

31
推荐指数
1
解决办法
1238
查看次数

从Spotify iOS应用程序获取当前播放的歌曲

我正在尝试获取有关Spotify iOS应用中当前播放歌曲的信息.方案如下:打开Spotify iOS应用程序,开始播放歌曲.将应用程序置于后台并打开我的iOS应用程序.有什么方法可以让我在iOS应用程序中的Spotify上播放这首歌吗?

我已尝试使用nowPlayingItem属性,如本文所述,但它不起作用:在iPhone上:找出当前正在播放的歌曲?(在iPod音乐播放器中)

我已尝试使用[MPNowPlayingInfoCenter defaultCenter] .nowPlayingInfo,如本文所述,但它不起作用:当iPhone连接到附件时,有没有办法访问当前播放的曲目?

我在苹果开发人员论坛上的帖子中看到了同样的问题:https://devforums.apple.com/message/903640#903640.

有谁遇到过这个问题?你找到了可行的解决方案吗?

谢谢,

spotify mpnowplayinginfocenter

30
推荐指数
2
解决办法
4417
查看次数

更改锁屏背景音频控制文字?

我有一个iOS应用程序,使用AVAudioSession流式传输背景音频.它工作正常,但我很好奇,有没有办法改变锁屏音频控件上的文字?现在它只显示我的应用程序的名称,但我想将其更改为轨道的名称.

此外,多任务栏在控件下没有文字 - 有没有办法在那里添加曲目名称,就像iPod应用程序一样?

objective-c ios avaudiosession mpnowplayinginfocenter swift

27
推荐指数
1
解决办法
9367
查看次数

将MPNowPlayingInfoCenter设置为播放其他背景音频

我正在尝试使用MPMoviePlayerController为Swift中的iOS应用播放视频.

我的目标是能够播放系统音乐,如苹果音乐,然后打开我的应用程序,并将音频混合,但我希望我的应用程序能够控制MPNowPlayingInfoCenter.

如何AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, withOptions: .MixWithOthers)在设置MPNowPlayingInfoCenter的同时使用?

设置MPNowPlayingInfoCenter时,Google地图会混合音频.以下是我尝试设置MPNowPlayingInfoCenter的方法:

func setMeta(){
    UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
    self.becomeFirstResponder()
    if let player = PlayWorkoutViewController.player{
        let coverArt = MPMediaItemArtwork(image: UIImage(named: "AlbumArt")!)
        let dict: [String: AnyObject] = [
            MPMediaItemPropertyArtwork: coverArt,
            MPMediaItemPropertyTitle:workout.title,
            MPMediaItemPropertyArtist:"Alex",
            MPMediaItemPropertyAlbumTitle:workout.program.title,
            MPNowPlayingInfoPropertyPlaybackRate: player.currentPlaybackRate,
            MPNowPlayingInfoPropertyElapsedPlaybackTime: player.currentPlaybackTime,
            MPMediaItemPropertyPlaybackDuration: player.playableDuration
        ]
        MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = dict
    }
}
Run Code Online (Sandbox Code Playgroud)

当我不想同时使用选项(.MixWithOthers)播放外部音乐时,上述功能有效,但是当我尝试使用选项(.MixWithOthers)播放外部音乐时,信息中心不会更新.

编辑1:为了让事情变得非常清楚,我已经正常播放视频我正在尝试使用其他背景音频播放视频,同时能够设置MPNowPlayingInfoCenter.

avfoundation ios mpnowplayinginfocenter swift

16
推荐指数
1
解决办法
2223
查看次数

MPNowPlayingInfoCenter - 经过的时间在音频暂停时保持计数

我目前正试图弄清楚如何MPNowPlayingInfoCenter在iOS上指定经过的时间.

当我开始播放时,我将经过时间设置为0并将播放速率设置为1.这样可以正常工作.

然后我暂停音频.这可以通过MPNowPlayingInfoCenter正确检测到,并暂停接口上的已用时间.

只有当我恢复播放时才会出现问题:时间显示就好像暂停时一直播放.例:

1. Start playback
2. Let it play for 10 seconds
3. Pause for 5 seconds
4. Resume playback
Run Code Online (Sandbox Code Playgroud)

此时,轨道中的实际时间为10秒.然而,信息中心显示15.

我试图在暂停时将播放速率设置为0,但这会导致一种奇怪的行为:显示的时间随机变为较低的值.

此外,我没有机会恢复歌曲之前更新已用时间,因为我在收到play活动后才有机会这样做.

tl; dr:如何处理MPNowPlayingInfoCenter中的暂停及其时间特征?

core-audio ios mpnowplayinginfocenter

15
推荐指数
1
解决办法
4636
查看次数

如何在iOS Lock Screen控制面板中启用音频滑块?

我有以下MPNowPlayingInfoCenter字典

@{MPMediaItemPropertyAlbumTitle: @"First Title",
                                MPMediaItemPropertyArtwork: [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"Album-Cover.jpg"]],
                                MPMediaItemPropertyPlaybackDuration:[NSNumber numberWithDouble:self.storyAudioPlayer.duration],
                                MPNowPlayingInfoPropertyElapsedPlaybackTime:[NSNumber numberWithDouble:self.storyAudioPlayer.currentTime],
                                MPNowPlayingInfoPropertyPlaybackRate:@1.0
                                }
Run Code Online (Sandbox Code Playgroud)

其他一切工作正常,但我无法使用滑块寻找歌曲.如图所示.我错过了什么参数?

锁屏截图

avaudioplayer ios avaudiosession mpnowplayinginfocenter

13
推荐指数
1
解决办法
4649
查看次数

MPNowPlayingInfoCenter nowPlayingInfo在轨道末尾不更新

我有一个方法可以改变我的应用程序播放的音轨,AVPlayer并设置MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo新的音轨:

func setTrackNumber(trackNum: Int) {
    self.trackNum = trackNum
    player.replaceCurrentItemWithPlayerItem(tracks[trackNum])

    var nowPlayingInfo: [String: AnyObject] = [ : ]        
    nowPlayingInfo[MPMediaItemPropertyAlbumTitle] = tracks[trackNum].albumTitle
    nowPlayingInfo[MPMediaItemPropertyTitle] = "Track \(trackNum)"
    ...
    MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = nowPlayingInfo 

    print("Now playing local: \(nowPlayingInfo)")
    print("Now playing lock screen: \(MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo)")   
}
Run Code Online (Sandbox Code Playgroud)

当用户明确选择专辑或曲目并且曲目结束并且下一曲目自动开始时,我会调用此方法.锁定屏幕在用户设置专辑或曲目时正确显示曲目元数据,但在曲目结束且自动设置下一曲目时不正确.

我添加了print语句以确保我正确填充nowPlayingInfo字典.正如所料,当调用此方法进行用户启动的专辑或曲目更改时,两个打印语句会打印相同的字典内容.但是,在自动跟踪更改后调用方法的情况下,局部nowPlayingInfo变量显示新的,trackNumMPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo显示前一个trackNum:

Now playing local: ["title": Track 9, "albumTitle": Test Album, ...]
Now playing set: Optional(["title": Track 8, "albumTitle": Test Album, ...]
Run Code Online (Sandbox Code Playgroud)

我发现,当我设置就行了断点,设置MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfonowPlayingInfo,然后曲目编号正确更新锁屏上.sleep(1) …

ios mpnowplayinginfocenter swift

13
推荐指数
1
解决办法
7183
查看次数

播放/暂停和已用时间未在iOS命令中心正确更新

我有一个可以从iOS命令中心和锁定屏幕播放的视频播放器.当我在我的应用程序切换播放/暂停按钮,它应该更新指挥中心(播放/暂停按钮,MPRemoteCommandCenter通过更新)nowPlayingInfo(MPNowPlayingInfoCenter).我不确定为什么它没有更新.

例如,如果我在我的应用程序中使用自定义按钮暂停视频,则命令中心仍会显示暂停按钮(意味着视频仍在播放,这是错误的.)

在此输入图像描述

这是我更新的方式nowPlayingInfo:

func updateMPNowPlayingInforCenterMetadata() {
    guard video != nil else {
        nowPlayingInfoCenter.nowPlayingInfo = nil
        return
    }

    var nowPlayingInfo = nowPlayingInfoCenter.nowPlayingInfo ?? [String: Any]()

    let image: UIImage
    if let placeholderLocalURL = video.placeholderLocalURL, let placeholderImage = UIImage(contentsOfFile: placeholderLocalURL.path) {
        image = placeholderImage
    } else {
        image = UIImage()
    }

    let artwork = MPMediaItemArtwork(boundsSize: image.size, requestHandler: { _ -> UIImage in
        return image
    })

    nowPlayingInfo[MPMediaItemPropertyTitle] = video.title
    nowPlayingInfo[MPMediaItemPropertyAlbumTitle] = video.creator?.name ?? " "
    nowPlayingInfo[MPMediaItemPropertyArtwork] …
Run Code Online (Sandbox Code Playgroud)

objective-c mpmediaitem ios mpnowplayinginfocenter swift

13
推荐指数
1
解决办法
2674
查看次数