//
// 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
github地址: https://github.com/cxsjabc/iphone-common-codes-ccteam/tree/master/CCFC/files/CCSound.m
本文介绍了CCSound类中用于监听音量变化的方法实现。通过使用MPMusicPlayerController及NSNotification来实现在iPod播放时对当前应用音量改变的通知。
73

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



