Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ios应用程序的MPMusicLayerController中获取当前播放的歌曲数据_Ios_Objective C_Mpmusicplayercontroller - Fatal编程技术网

如何在ios应用程序的MPMusicLayerController中获取当前播放的歌曲数据

如何在ios应用程序的MPMusicLayerController中获取当前播放的歌曲数据,ios,objective-c,mpmusicplayercontroller,Ios,Objective C,Mpmusicplayercontroller,我正在MPMusicLayerController中播放歌曲,现在我想获取当前播放的歌曲数据(例如:some.mp3) 请帮助我,提前谢谢您可以向MPMusicLayerController询问当前播放的歌曲 MPMediaItem *songItem = [controller nowPlayingItem]; 然后,要提取文件(如mp3中的文件),有以下步骤。查看前两个答案。您可以向MPMusicLayerController询问当前播放的歌曲 MPMediaItem *songIte

我正在MPMusicLayerController中播放歌曲,现在我想获取当前播放的歌曲数据(例如:some.mp3)


请帮助我,提前谢谢

您可以向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”来检查