如何在ios应用程序的MPMusicLayerController中获取当前播放的歌曲数据
我正在MPMusicLayerController中播放歌曲,现在我想获取当前播放的歌曲数据(例如:some.mp3)如何在ios应用程序的MPMusicLayerController中获取当前播放的歌曲数据,ios,objective-c,mpmusicplayercontroller,Ios,Objective C,Mpmusicplayercontroller,我正在MPMusicLayerController中播放歌曲,现在我想获取当前播放的歌曲数据(例如:some.mp3) 请帮助我,提前谢谢您可以向MPMusicLayerController询问当前播放的歌曲 MPMediaItem *songItem = [controller nowPlayingItem]; 然后,要提取文件(如mp3中的文件),有以下步骤。查看前两个答案。您可以向MPMusicLayerController询问当前播放的歌曲 MPMediaItem *songIte
请帮助我,提前谢谢您可以向MPMusicLayerController询问当前播放的歌曲
MPMediaItem *songItem = [controller nowPlayingItem];
然后,要提取文件(如mp3中的文件),有以下步骤。查看前两个答案。您可以向MPMusicLayerController询问当前播放的歌曲
MPMediaItem *songItem = [controller nowPlayingItem];
然后,要提取文件(如mp3中的文件),有以下步骤。看看前两个答案。试试这一个
@property (nonatomic, retain) MPMusicPlayerController *musicPlayer;
@property (nonatomic, retain) IBOutlet UILabel *songLabel;
@property (nonatomic, retain) IBOutlet UILabel *artistLabel;
@property (nonatomic, retain) IBOutlet UILabel *albumLabel;
- (void)handleNowPlayingItemChanged:(id)notification
{
// Ask the music player for the current song.
MPMediaItem *currentItem = self.musicPlayer.nowPlayingItem;
// Display the artist, album, and song name for the now-playing media item.
// These are all UILabels.
self.songLabel.text = [currentItem valueForProperty:MPMediaItemPropertyTitle];
self.artistLabel.text = [currentItem valueForProperty:MPMediaItemPropertyArtist];
self.albumLabel.text = [currentItem valueForProperty:MPMediaItemPropertyAlbumTitle];
// Display album artwork. self.artworkImageView is a UIImageView.
CGSize artworkImageViewSize = self.artworkImageView.bounds.size;
MPMediaItemArtwork *artwork = [currentItem valueForProperty:MPMediaItemPropertyArtwork];
if (artwork != nil)
{
self.artworkImageView.image = [artwork imageWithSize:artworkImageViewSize];
}
else
{
self.artworkImageView.image = nil;
}
}
试试这个
@property (nonatomic, retain) MPMusicPlayerController *musicPlayer;
@property (nonatomic, retain) IBOutlet UILabel *songLabel;
@property (nonatomic, retain) IBOutlet UILabel *artistLabel;
@property (nonatomic, retain) IBOutlet UILabel *albumLabel;
- (void)handleNowPlayingItemChanged:(id)notification
{
// Ask the music player for the current song.
MPMediaItem *currentItem = self.musicPlayer.nowPlayingItem;
// Display the artist, album, and song name for the now-playing media item.
// These are all UILabels.
self.songLabel.text = [currentItem valueForProperty:MPMediaItemPropertyTitle];
self.artistLabel.text = [currentItem valueForProperty:MPMediaItemPropertyArtist];
self.albumLabel.text = [currentItem valueForProperty:MPMediaItemPropertyAlbumTitle];
// Display album artwork. self.artworkImageView is a UIImageView.
CGSize artworkImageViewSize = self.artworkImageView.bounds.size;
MPMediaItemArtwork *artwork = [currentItem valueForProperty:MPMediaItemPropertyArtwork];
if (artwork != nil)
{
self.artworkImageView.image = [artwork imageWithSize:artworkImageViewSize];
}
else
{
self.artworkImageView.image = nil;
}
}
还有什么方法可以检查这句话是真的在播放还是暂停了?@NoSixties你可以使用MPMusicPlayerController的“playbackState”来检查这句话是真的在播放还是暂停了?@NoSixties你可以使用MPMusicPlayerController的“playbackState”来检查