Iphone 如何在UILabel中插入Now Playing
我试图在iOS 5上抓取当前正在播放的歌曲,并将艺术家和标题转储到UILabel中。这可能吗 据我所知,我将使用以前版本的操作系统Iphone 如何在UILabel中插入Now Playing,iphone,objective-c,xcode,ios5,Iphone,Objective C,Xcode,Ios5,我试图在iOS 5上抓取当前正在播放的歌曲,并将艺术家和标题转储到UILabel中。这可能吗 据我所知,我将使用以前版本的操作系统 MPMediaPlayer* player = [MPMediaPlayer iPodMusicPlayer]; //get now playing item MPMediaItem*item = [player nowPlayingItem]; // get the title of song NSString* titleStr = [item valueFor
MPMediaPlayer* player = [MPMediaPlayer iPodMusicPlayer];
//get now playing item
MPMediaItem*item = [player nowPlayingItem];
// get the title of song
NSString* titleStr = [item valueForProperty:MPMediaItemPropertyTitle];
但这会产生一些警告,而且不起作用。任何帮助都将不胜感激
谢谢我试图编译您的代码,但看起来您使用了错误的类。您需要的是MPMusicLayerController,而不是MPMediaPlayer
MPMusicPlayerController* player = [MPMusicPlayerController iPodMusicPlayer];
//get now playing item
MPMediaItem*item = [player nowPlayingItem];
// get the title of song
NSString* titleStr = [item valueForProperty:MPMediaItemPropertyTitle];
编译时没有警告,我没有在设备上测试过,但这应该会有帮助。我试图编译您的代码,但看起来您使用了错误的类。您需要的是MPMusicLayerController,而不是MPMediaPlayer
MPMusicPlayerController* player = [MPMusicPlayerController iPodMusicPlayer];
//get now playing item
MPMediaItem*item = [player nowPlayingItem];
// get the title of song
NSString* titleStr = [item valueForProperty:MPMediaItemPropertyTitle];
编译时没有警告,我还没有在设备上测试过,但这应该会有帮助。您收到了什么警告?您收到了什么警告?谢谢大家,这似乎解决了问题。再次感谢汉克斯,这似乎解决了问题。再次感谢