检测音乐是否正在播放?
我的应用程序涉及音乐(iPodMusic),并且有一个 UISwitch 切换播放/暂停。我的目标是能够检测音乐是否正在播放,以便播放/暂停开关可以在音乐播放时说“播放”,如果没有播放音乐则说“暂停”。
My app involves music(iPodMusic), and there is a UISwitch toggling play/pause. My goal is to be able to detect if music is playing, so that therefore the play/pause switch can say 'play' when music is playing and 'pause' if it isn't.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果音乐来自您自己的应用程序,请检查 AVAudioPlayer 的
playing
属性。如果音乐来自 iPod,请检查 MPMusicPlayerController 的
nowPlayingItem
或playbackState
属性。If the music is from your own app, check AVAudioPlayer's
playing
property.If the music is from iPod, check MPMusicPlayerController's
nowPlayingItem
orplaybackState
property.MPMusicPlayerController 仅适用于 OS 3.0 或更高版本。如果你运行的是 2.0,那你就不走运了。下面是一个代码片段,用于检查您是否正在运行 3.0 或更高版本,然后才尝试创建 MPMuiscPlayerController
您必须针对 3.0 SDK 进行编译,但如果您将部署目标设置为 2.0,则此代码仍然可以在较旧的设备上运行。
MPMusicPlayerController is only available in OS 3.0 or above. If you're running 2.0 you're out of luck. Here's a code snippet that checks if you're running 3.0 or above and only then attempts to create an MPMuiscPlayerController
You have to compile against a 3.0 SDK, but if you set the deployment target to 2.0, this code still runs on older devices.
如果你的 iTunes 声音打开,它会变成 yes,否则如果 iTunes 音乐播放器的声音关闭,它会变成 no ... 所以你可以轻松检查默认的 MusicPlayer 声音是打开还是关闭 你需要添加媒体播放器框架 Just Try It it会正常工作...谢谢...:)
it goes to yes if your iTunes sound is on else it goes to no if sound is off of iTunes music player ... So You can check easily default MusicPlayer Sound is On or Off You need to add media-player Framework Just Try It it will work Properly.... Thx...:)