// // CCSound.m // CCFC // // Created by xichen on 12-1-3. // Copyright 2012 ccteam. All rights reserved. // #import "CCSound.h" #import <MediaPlayer/MediaPlayer.h> @implementation CCSound // add a volume changed observer event // the selector will be only called when the ipod player is playing and the current application is active + (void)addVolumeChangeObserver:(id)observer sel:(SEL)sel { MPMusicPlayerController *musicPlayer = [MPMusicPlayerController iPodMusicPlayer]; [musicPlayer beginGeneratingPlaybackNotifications]; [[NSNotificationCenter defaultCenter] addObserver:observer selector:sel name:MPMusicPlayerControllerVolumeDidChangeNotification object:musicPlayer]; } @end可能有更新:
googlecode链接地址: http://code.google.com/p/iphone-common-codes-ccteam/source/browse/trunk/CCFC/files/CCSound.m
googlecode链接地址: http://code.google.com/p/iphone-common-codes-ccteam/source/browse/trunk/CCFC/files/CCSound.m
github地址: https://github.com/cxsjabc/iphone-common-codes-ccteam/tree/master/CCFC/files/CCSound.m
本文详细解读了CCSound.m文件中实现的音乐播放器音量变化观察者模式,包括如何添加音量变化的监听器,以及在不同场景下的应用实例。重点介绍了通过MPMusicPlayerController接口获取音乐播放器状态并进行音量调整的技术细节。
73

被折叠的 条评论
为什么被折叠?



