iOS 8 : Get title of song being played by the system music player
<p><p>我正在尝试获取默认音乐应用当前正在播放的歌曲的标题。方法如下:</p>
<pre><code>- (NSString*)getSongTitle {
MPMediaItem *currentSong = [ nowPlayingItem];
_title = ;
NSLog(_title);
return _title;
}
</code></pre>
<p>我在网上阅读的所有内容都表明这应该是正确的,但是 <code>_title</code> 每次都被分配 <code>nil</code> 。有什么想法吗?</p>
<p>顺便说一句,我有@imported <code>MediaPlayer</code>。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我认为您只是使用了错误的 key 。试试 <code>MPMediaItemPropertyTitle</code>。它应该看起来像这样:</p>
<pre><code>- (NSString*)getSongTitle {
MPMediaItem *currentSong = [ nowPlayingItem];
_title = ;
NSLog(_title);
return _title;
}
</code></pre></p>
<p style="font-size: 20px;">关于iOS 8 : Get title of song being played by the system music player,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/31481255/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/31481255/
</a>
</p>
页:
[1]