锁屏状态下,看到歌手图片

第一步,检查你的AppDelegate是不是继承于UIResponder,有的是自动生成,有的人习惯手写,如果是继承于NSObject请改为 AppDelegate : UIResponder
第二步,在音乐播放的时候,写上歌曲信息和图片信息:

- (void) setMediaInfo : (UIImage *) img andTitle : (NSString *) title andArtist : (NSString *) artist
{
MYDEBUGPRINT(NSLog(@"begen set album art, to MPNowPlayingInfoCenter."));
if (NSClassFromString(@"MPNowPlayingInfoCenter")) {
NSMutableDictionary * dict = [[NSMutableDictionary alloc] init];


[dict setObject:title forKey:MPMediaItemPropertyAlbumTitle];
[dict setObject:artist forKey:MPMediaItemPropertyArtist];
[dict setObject:[NSNumber numberWithInt:[playlist.refresh intValue]] forKey:MPMediaItemPropertyPlaybackDuration];


MPMediaItemArtwork * mArt = [[MPMediaItemArtwork alloc] initWithImage:img];
[dict setObject:mArt forKey:MPMediaItemPropertyArtwork];
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nil;
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:dict];
[dict release];
}
}
上面的if (NSClassFromString(@"MPNowPlayingInfoCenter"))避免了版本兼容问题,这个API貌似只出现在5里面。


现在你可以发现,上面的代码可能不起作用,而且待机屏的播放暂停也不会起作用。
第三步,在appDelegate的加载完成回调里面写
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
你会发现,,只有信息出来,但是播放控制还是不起作用。。。。。

呵呵,绕弯子了。


重写这个方法了
- (BOOL) canBecomeFirstResponder {
return YES;
}

- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {

if (receivedEvent.type == UIEventTypeRemoteControl) {

switch (receivedEvent.subtype) {

case UIEventSubtypeRemoteControlTogglePlayPause:
NSLog(@"xxxxxxxxxxx11111");
break;
case UIEventSubtypeRemoteControlNextTrack:
NSLog(@"xxxxxxxxxxx3333");
break;
case UIEventSubtypeRemoteControlPreviousTrack:
NSLog(@"xxxxxxxxxxx4444");
break;
default:
break;
}
}
}


OK,炫炫的效果出来了,,,,,
当然becomeFirstResponder也可以写在ViewControll或者View里面。
但是作为整个应用的状态来说,个人认为,写在appDelegate比较好。

这里有点考虑,becomeFirstResponder后,会不会对应用的某些功能有影响,,,


最后附MPNowPlayingInfoCenter可显示的内容,但是本人还有些没有试出来,,不知为何。。。

some properties specific to this class. In iOS 5.0, the now playing info center supports the following media item property keys:

MPMediaItemPropertyAlbumTitle
MPMediaItemPropertyAlbumTrackCount
MPMediaItemPropertyAlbumTrackNumber
MPMediaItemPropertyArtist
MPMediaItemPropertyArtwork
MPMediaItemPropertyComposer
MPMediaItemPropertyDiscCount
MPMediaItemPropertyDiscNumber
MPMediaItemPropertyGenre
MPMediaItemPropertyPersistentID
MPMediaItemPropertyPlaybackDuration
MPMediaItemPropertyTitle


Additional Metadata Properties
These properties for the now playing info center dictionary supplement the available media item properties, as described in the Overview in this document.

NSString *const MPNowPlayingInfoPropertyElapsedPlaybackTime
NSString *const MPNowPlayingInfoPropertyPlaybackRate;
NSString *const MPNowPlayingInfoPropertyPlaybackQueueIndex;
NSString *const MPNowPlayingInfoPropertyPlaybackQueueCount;
NSString *const MPNowPlayingInfoPropertyChapterNumber;
NSString *const MPNowPlayingInfoPropertyChapterCount;


http://tieba.baidu.com/p/1394006679
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值