diff --git a/Class/MPVolumeObserver.h b/Class/MPVolumeObserver.h index cde14ad..afdd01c 100755 --- a/Class/MPVolumeObserver.h +++ b/Class/MPVolumeObserver.h @@ -1,12 +1,18 @@ // Created by tashigaofei on 13/08/26. +// Change by LJT on 17/01/15 #import #import #import +#import @class MPVolumeObserver; @protocol MPVolumeObserverProtocol --(void) volumeButtonDidClick:(MPVolumeObserver *) button; +-(void) volumeButtonCameraClick:(MPVolumeObserver *) button; +-(void) volumeButtonStarVideoClick:(MPVolumeObserver *) button; +-(void) volumeButtonEndVideoClick:(MPVolumeObserver *) button; + + @end diff --git a/Class/MPVolumeObserver.m b/Class/MPVolumeObserver.m index 0868b52..79e110b 100755 --- a/Class/MPVolumeObserver.m +++ b/Class/MPVolumeObserver.m @@ -1,17 +1,22 @@ - -// Created by tashigaofei on 13/08/26. -// - #import "MPVolumeObserver.h" @interface MPVolumeObserver() { - UIView *_volumeView; - float launchVolume; - BOOL _isObservingVolumeButtons; - BOOL _suspended; + MPVolumeView *_volumeView; + float launchVolume; + BOOL _isObservingVolumeButtons; + BOOL _suspended; + int Isfirst; + NSString *strNowVolume; + NSTimer *timeVideoBtn; + NSInteger secondsElapsed; + BOOL isVideoStar; + BOOL isVideoEnd; + + float fVolume; } + @end @implementation MPVolumeObserver @@ -33,42 +38,41 @@ -(id)init if( self ){ _isObservingVolumeButtons = NO; _suspended = NO; - CGRect frame = CGRectMake(0, -100, 0, 0); - _volumeView = [[MPVolumeView alloc] initWithFrame:frame]; - [[UIApplication sharedApplication].windows[0] addSubview:_volumeView]; - + Isfirst = 0; + secondsElapsed = 0; + } return self; } -(void)startObserveVolumeChangeEvents { - double delayInSeconds = 0.25; - dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); - dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ - [self startObserve]; - }); + _suspended = NO; + isVideoStar = YES; + isVideoEnd = NO; + fVolume = [self volume]; + [self startObserve]; } -(void) startObserve; { - if(_isObservingVolumeButtons) { + NSLog(@"start add notification"); + if(_isObservingVolumeButtons) + { return; } _isObservingVolumeButtons = YES; - AudioSessionInitialize(NULL, NULL, NULL, NULL); - SInt32 process = kAudioSessionCategory_AmbientSound; - AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(process), &process); - AudioSessionSetActive(YES); - - launchVolume = [[MPMusicPlayerController applicationMusicPlayer] volume]; - launchVolume = launchVolume == 0 ? 0.05 : launchVolume; - launchVolume = launchVolume == 1 ? 0.95 : launchVolume; - if (launchVolume == 0.05 || launchVolume == 0.95) { - [[MPMusicPlayerController applicationMusicPlayer] setVolume:launchVolume]; + CGRect frame = CGRectMake(0, -100, 0, 0); + _volumeView = [[MPVolumeView alloc] initWithFrame:frame]; + [[UIApplication sharedApplication].windows[0] addSubview:_volumeView]; + strNowVolume = [[ NSString stringWithFormat:@"%f",[self volume] ] substringToIndex:4]; + strNowVolume = [strNowVolume isEqual: @"0.00"] ? @"0.05" : strNowVolume; + strNowVolume = [strNowVolume isEqual: @"1.00"] ? @"0.95" : strNowVolume; + if ([strNowVolume isEqual: @"0.05"] || [strNowVolume isEqualToString:@"0.95"]) + { + [self setVolume:[strNowVolume floatValue]]; } - if (!_suspended) { [[NSNotificationCenter defaultCenter] addObserver:self @@ -84,8 +88,6 @@ -(void) startObserve; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChangeNotification:) name:@"SystemVolumeDidChange" object:nil]; } - - } -(void) volumeChangeNotification:(NSNotification *) no @@ -95,17 +97,74 @@ -(void) volumeChangeNotification:(NSNotification *) no sender = no.object; } - if (no.object != sender || [[no.userInfo objectForKey:@"AudioVolume"] floatValue] == launchVolume) { + NSString * NowChangeVolume = [[ NSString stringWithFormat:@"%f",[[no.userInfo objectForKey:@"AudioVolume"] floatValue] ] substringToIndex:4]; + if (no.object != sender || [NowChangeVolume isEqualToString: strNowVolume]) { return; } - [[MPMusicPlayerController applicationMusicPlayer] setVolume:launchVolume]; - - if ([_delegate respondsToSelector:@selector(volumeButtonDidClick:)]) { - [_delegate volumeButtonDidClick:self]; + [self setVolume:fVolume]; + if(timeVideoBtn) + { + if(secondsElapsed == 1) + { + if (isVideoStar) + { + NSLog(@"start video"); + if ([self.delegate respondsToSelector:@selector(volumeButtonStarVideoClick:)]) { + [self.delegate volumeButtonStarVideoClick:self]; + } + isVideoStar = NO; + isVideoEnd = YES; + } + } + secondsElapsed ++; + [timeVideoBtn invalidate]; } -// NSLog(@"\n\n%@\n\n", no); + timeVideoBtn = [NSTimer scheduledTimerWithTimeInterval:0.2 + target:self + selector:@selector(onTimeFire) + userInfo:nil + repeats:NO]; +} + +-(void)onTimeFire +{ + + timeVideoBtn = nil; + + if (secondsElapsed > 2) + { + if (isVideoEnd) { + secondsElapsed = 0; + NSLog(@"end video"); + if ([self.delegate respondsToSelector:@selector(volumeButtonEndVideoClick:)]) { + [self.delegate volumeButtonEndVideoClick:self]; + isVideoEnd = NO; + } + } + } + else + { + double delayInSeconds = 0.65; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self tackPhoto]; + }); + } +} + + + + +- (void)tackPhoto +{ + if (isVideoStar) + { + NSLog(@"take Photo"); + if ([self.delegate respondsToSelector:@selector(volumeButtonCameraClick:)]) { + [self.delegate volumeButtonCameraClick:self]; + } + } } @@ -115,6 +174,7 @@ - (void)suspendObserveVolumeChangeEvents:(NSNotification *)notification { _suspended = YES; // Call first! [self stopObserveVolumeChangeEvents]; + Isfirst = 0; } } @@ -123,6 +183,7 @@ - (void)resumeObserveVolumeButtonEvents:(NSNotification *)notification if(_suspended) { [self startObserveVolumeChangeEvents]; + Isfirst = 0; _suspended = NO; // Call last! } } @@ -134,20 +195,42 @@ -(void)stopObserveVolumeChangeEvents return; } - if (!_suspended){ - [[NSNotificationCenter defaultCenter] removeObserver:self]; - } - AudioSessionRemovePropertyListenerWithUserData(kAudioSessionProperty_CurrentHardwareOutputVolume, NULL, self); - AudioSessionSetActive(NO); - + [[NSNotificationCenter defaultCenter]removeObserver:self name:@"SystemVolumeDidChange" object:nil]; + + Isfirst = 0; + [timeVideoBtn invalidate]; + secondsElapsed = 0; _isObservingVolumeButtons = NO; } +- (float)volume +{ + AVAudioSession *audioSession = [AVAudioSession sharedInstance]; + CGFloat volume = audioSession.outputVolume; + return volume; +} + +- (void)setVolume:(float)newVolume +{ + MPVolumeView* volumeView = [[MPVolumeView alloc] init]; + + //find the volumeSlider + UISlider* volumeViewSlider = nil; + for (UIView *view in [volumeView subviews]){ + if ([view.class.description isEqualToString:@"MPVolumeSlider"]){ + volumeViewSlider = (UISlider*)view; + break; + } + } + + [volumeViewSlider setValue:newVolume animated:YES]; + [volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside]; +} -(void)dealloc { - _suspended = NO; - [super dealloc]; + _suspended = NO; + Isfirst = 0; } @end diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/project.pbxproj b/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/project.pbxproj old mode 100644 new mode 100755 index 41bbbfd..7f3b15a --- a/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/project.pbxproj +++ b/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/project.pbxproj @@ -20,6 +20,8 @@ 819FF5F117D5F0A500E5A227 /* MPVolumeObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 819FF5F017D5F0A500E5A227 /* MPVolumeObserver.m */; }; 819FF5F317D5F0B900E5A227 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 819FF5F217D5F0B900E5A227 /* AudioToolbox.framework */; }; 819FF5F717D5F0DE00E5A227 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 819FF5F617D5F0DE00E5A227 /* MediaPlayer.framework */; }; + D0680E6E1E2DFD2700B8B0EB /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0680E6D1E2DFD2700B8B0EB /* AVFoundation.framework */; }; + D0680E711E2DFD7C00B8B0EB /* PushVC.m in Sources */ = {isa = PBXBuildFile; fileRef = D0680E701E2DFD7C00B8B0EB /* PushVC.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -42,6 +44,9 @@ 819FF5F017D5F0A500E5A227 /* MPVolumeObserver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPVolumeObserver.m; sourceTree = ""; }; 819FF5F217D5F0B900E5A227 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 819FF5F617D5F0DE00E5A227 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; }; + D0680E6D1E2DFD2700B8B0EB /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; + D0680E6F1E2DFD7C00B8B0EB /* PushVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PushVC.h; sourceTree = ""; }; + D0680E701E2DFD7C00B8B0EB /* PushVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PushVC.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -49,6 +54,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + D0680E6E1E2DFD2700B8B0EB /* AVFoundation.framework in Frameworks */, 819FF5F717D5F0DE00E5A227 /* MediaPlayer.framework in Frameworks */, 819FF5F317D5F0B900E5A227 /* AudioToolbox.framework in Frameworks */, 819FF5C817D5F01200E5A227 /* UIKit.framework in Frameworks */, @@ -80,6 +86,7 @@ 819FF5C617D5F01200E5A227 /* Frameworks */ = { isa = PBXGroup; children = ( + D0680E6D1E2DFD2700B8B0EB /* AVFoundation.framework */, 819FF5F617D5F0DE00E5A227 /* MediaPlayer.framework */, 819FF5F217D5F0B900E5A227 /* AudioToolbox.framework */, 819FF5C717D5F01200E5A227 /* UIKit.framework */, @@ -97,6 +104,8 @@ 819FF5D717D5F01200E5A227 /* AppDelegate.m */, 819FF5DF17D5F01200E5A227 /* ViewController.h */, 819FF5E017D5F01200E5A227 /* ViewController.m */, + D0680E6F1E2DFD7C00B8B0EB /* PushVC.h */, + D0680E701E2DFD7C00B8B0EB /* PushVC.m */, 819FF5CE17D5F01200E5A227 /* Supporting Files */, ); path = MPLovumeObserveDemo; @@ -154,6 +163,11 @@ attributes = { LastUpgradeCheck = 0460; ORGANIZATIONNAME = baidu; + TargetAttributes = { + 819FF5C317D5F01200E5A227 = { + DevelopmentTeam = WEFT5XRB8Z; + }; + }; }; buildConfigurationList = 819FF5BF17D5F01200E5A227 /* Build configuration list for PBXProject "MPLovumeObserveDemo" */; compatibilityVersion = "Xcode 3.2"; @@ -194,6 +208,7 @@ 819FF5D417D5F01200E5A227 /* main.m in Sources */, 819FF5D817D5F01200E5A227 /* AppDelegate.m in Sources */, 819FF5E117D5F01200E5A227 /* ViewController.m in Sources */, + D0680E711E2DFD7C00B8B0EB /* PushVC.m in Sources */, 819FF5F117D5F0A500E5A227 /* MPVolumeObserver.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -269,6 +284,8 @@ 819FF5E817D5F01200E5A227 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_ARC = YES; + DEVELOPMENT_TEAM = WEFT5XRB8Z; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "\"$(SDKROOT)$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"", @@ -276,7 +293,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "MPLovumeObserveDemo/MPLovumeObserveDemo-Prefix.pch"; INFOPLIST_FILE = "MPLovumeObserveDemo/MPLovumeObserveDemo-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -285,6 +302,8 @@ 819FF5E917D5F01200E5A227 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_ARC = YES; + DEVELOPMENT_TEAM = WEFT5XRB8Z; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "\"$(SDKROOT)$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"", @@ -292,7 +311,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "MPLovumeObserveDemo/MPLovumeObserveDemo-Prefix.pch"; INFOPLIST_FILE = "MPLovumeObserveDemo/MPLovumeObserveDemo-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -317,6 +336,7 @@ 819FF5E917D5F01200E5A227 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/project.xcworkspace/xcuserdata/tashigaofei.xcuserdatad/WorkspaceSettings.xcsettings b/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/project.xcworkspace/xcuserdata/tashigaofei.xcuserdatad/WorkspaceSettings.xcsettings old mode 100644 new mode 100755 diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/project.xcworkspace/xcuserdata/xiujiekeman.xcuserdatad/UserInterfaceState.xcuserstate b/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/project.xcworkspace/xcuserdata/xiujiekeman.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..c68603a Binary files /dev/null and b/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/project.xcworkspace/xcuserdata/xiujiekeman.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/xcuserdata/tashigaofei.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist b/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/xcuserdata/tashigaofei.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist old mode 100644 new mode 100755 diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/xcuserdata/tashigaofei.xcuserdatad/xcschemes/MPLovumeObserveDemo.xcscheme b/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/xcuserdata/tashigaofei.xcuserdatad/xcschemes/MPLovumeObserveDemo.xcscheme old mode 100644 new mode 100755 diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/xcuserdata/tashigaofei.xcuserdatad/xcschemes/xcschememanagement.plist b/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/xcuserdata/tashigaofei.xcuserdatad/xcschemes/xcschememanagement.plist old mode 100644 new mode 100755 diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/xcuserdata/xiujiekeman.xcuserdatad/xcschemes/MPLovumeObserveDemo.xcscheme b/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/xcuserdata/xiujiekeman.xcuserdatad/xcschemes/MPLovumeObserveDemo.xcscheme new file mode 100644 index 0000000..247a7c4 --- /dev/null +++ b/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/xcuserdata/xiujiekeman.xcuserdatad/xcschemes/MPLovumeObserveDemo.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/xcuserdata/xiujiekeman.xcuserdatad/xcschemes/xcschememanagement.plist b/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/xcuserdata/xiujiekeman.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..9fb91ce --- /dev/null +++ b/MPLovumeObserveDemo/MPLovumeObserveDemo.xcodeproj/xcuserdata/xiujiekeman.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + MPLovumeObserveDemo.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 819FF5C317D5F01200E5A227 + + primary + + + + + diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo/AppDelegate.h b/MPLovumeObserveDemo/MPLovumeObserveDemo/AppDelegate.h old mode 100644 new mode 100755 diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo/AppDelegate.m b/MPLovumeObserveDemo/MPLovumeObserveDemo/AppDelegate.m old mode 100644 new mode 100755 index 58b0998..187140e --- a/MPLovumeObserveDemo/MPLovumeObserveDemo/AppDelegate.m +++ b/MPLovumeObserveDemo/MPLovumeObserveDemo/AppDelegate.m @@ -12,19 +12,14 @@ @implementation AppDelegate -- (void)dealloc -{ - [_window release]; - [_viewController release]; - [super dealloc]; -} - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ; // Override point for customization after application launch. - self.viewController = [[[ViewController alloc] init] autorelease]; - self.window.rootViewController = self.viewController; + self.viewController = [[ViewController alloc] init] ; + UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:self.viewController]; + self.window.rootViewController = nav; [self.window makeKeyAndVisible]; return YES; } diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo/Default-568h@2x.png b/MPLovumeObserveDemo/MPLovumeObserveDemo/Default-568h@2x.png old mode 100644 new mode 100755 diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo/Default.png b/MPLovumeObserveDemo/MPLovumeObserveDemo/Default.png old mode 100644 new mode 100755 diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo/Default@2x.png b/MPLovumeObserveDemo/MPLovumeObserveDemo/Default@2x.png old mode 100644 new mode 100755 diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo/MPLovumeObserveDemo-Info.plist b/MPLovumeObserveDemo/MPLovumeObserveDemo/MPLovumeObserveDemo-Info.plist old mode 100644 new mode 100755 diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo/MPLovumeObserveDemo-Prefix.pch b/MPLovumeObserveDemo/MPLovumeObserveDemo/MPLovumeObserveDemo-Prefix.pch old mode 100644 new mode 100755 diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo/PushVC.h b/MPLovumeObserveDemo/MPLovumeObserveDemo/PushVC.h new file mode 100644 index 0000000..594f25a --- /dev/null +++ b/MPLovumeObserveDemo/MPLovumeObserveDemo/PushVC.h @@ -0,0 +1,13 @@ +// +// PushVC.h +// MPLovumeObserveDemo +// +// Created by 休杰克曼 on 2017/1/17. +// Copyright © 2017年 baidu. All rights reserved. +// + +#import + +@interface PushVC : UIViewController + +@end diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo/PushVC.m b/MPLovumeObserveDemo/MPLovumeObserveDemo/PushVC.m new file mode 100644 index 0000000..765f612 --- /dev/null +++ b/MPLovumeObserveDemo/MPLovumeObserveDemo/PushVC.m @@ -0,0 +1,38 @@ +// +// PushVC.m +// MPLovumeObserveDemo +// +// Created by 休杰克曼 on 2017/1/17. +// Copyright © 2017年 baidu. All rights reserved. +// + +#import "PushVC.h" + +@interface PushVC () + +@end + +@implementation PushVC + +- (void)viewDidLoad { + [super viewDidLoad]; + self.view.backgroundColor = [UIColor orangeColor]; + // Do any additional setup after loading the view. +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ + +@end diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo/ViewController.h b/MPLovumeObserveDemo/MPLovumeObserveDemo/ViewController.h old mode 100644 new mode 100755 diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo/ViewController.m b/MPLovumeObserveDemo/MPLovumeObserveDemo/ViewController.m old mode 100644 new mode 100755 index 6186d16..d66b2f2 --- a/MPLovumeObserveDemo/MPLovumeObserveDemo/ViewController.m +++ b/MPLovumeObserveDemo/MPLovumeObserveDemo/ViewController.m @@ -8,6 +8,7 @@ #import "ViewController.h" #import "MPVolumeObserver.h" +#import "PushVC.h" @interface ViewController () @@ -21,23 +22,55 @@ - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; - +} + +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; [MPVolumeObserver sharedInstance].delegate = self; - [[MPVolumeObserver sharedInstance] startObserveVolumeChangeEvents]; - + [[MPVolumeObserver sharedInstance]startObserveVolumeChangeEvents]; } + +- (void)viewDidDisappear:(BOOL)animated +{ + [super viewDidDisappear:animated]; + [MPVolumeObserver sharedInstance].delegate = nil; + [[MPVolumeObserver sharedInstance]stopObserveVolumeChangeEvents]; +} + + + +-(void) volumeButtonCameraClick:(MPVolumeObserver *) button +{ + NSLog(@"take Photo"); + PushVC *vc = [[PushVC alloc]init]; + [self.navigationController pushViewController:vc animated:YES]; + +} + + +-(void) volumeButtonStarVideoClick:(MPVolumeObserver *) button +{ + NSLog(@"start video"); +} + + +-(void) volumeButtonEndVideoClick:(MPVolumeObserver *) button +{ + NSLog(@"end Video"); + PushVC *vc = [[PushVC alloc]init]; + [self.navigationController pushViewController:vc animated:YES]; + +} + + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } --(void) volumeButtonDidClick:(MPVolumeObserver *) button; -{ - NSLog(@"change"); - -} @end diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo/en.lproj/InfoPlist.strings b/MPLovumeObserveDemo/MPLovumeObserveDemo/en.lproj/InfoPlist.strings old mode 100644 new mode 100755 diff --git a/MPLovumeObserveDemo/MPLovumeObserveDemo/main.m b/MPLovumeObserveDemo/MPLovumeObserveDemo/main.m old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755