相关疑难解决方法(0)

从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
查看次数

MPMusicPlayerController没有发布通知?

我正在尝试使用MPMusicPlayerController播放音乐,我也希望收到通知MPMusicPlayerControllerPlaybackStateDidChange.我设置我的播放器和通知注册就像样本一样(有效,BTW - 它正确接收通知):

- (id) initWithPlaylist:(MPMediaPlaylist*)list {
    if (self = [super init]) {
        player = [MPMusicPlayerController applicationMusicPlayer];
        [player retain];

        NSLog(@"setting up player");
        [plaayer setQueueWithItemCollection:list];
        [player setShuffleMode:MPMusicShuffleModeOff];
        [player setRepeatMode:MPMusicRepeatModeNone];

        NSLog(@"registering MPMusicPlayerController Notifications");
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(handle_itemChanged:) 
                                                     name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification 
                                                   object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(handle_stateChanged:)
                                                     name:MPMusicPlayerControllerPlaybackStateDidChangeNotification
                                                   object:nil];

        NSLog(@"turning on player notifications");
        [player beginGeneratingPlaybackNotifications];
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到了很多bupkis.这些方法handle_itemChanged:handle_stateChanged:是除了一个是空洞的NSLog声明,表明他们已经被击中,而且也从未出现,他们被打到.将按预期将NSLog语句initWithPlaylist:打印到日志中.以上只是我的应用程序中的业务对象.它不是视图或视图控制器.

有任何想法吗?奇怪的是,AddMusic样本对我来说效果很好,而且我不能说我MPMusicPlayerController对它及其通知做了什么不同的事情.

更新:我在我的应用代理中添加了这一行,以查看大量的通知:

[[NSNotificationCenter defaultCenter] addObserverForName:nil object:nil queue:nil usingBlock:^(NSNotification *n) …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch ios

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