// // JXStartSoundView.m // shiku_im // // Created by 123 on 2020/6/12. // Copyright © 2020 Reese. All rights reserved. // #import "JXStartSoundView.h" @interface JXStartSoundView() @end @implementation JXStartSoundView -(instancetype)initWithFrame:(CGRect)frame{ if (self=[super initWithFrame:frame]) { } return self; } -(void)createSoundStrUrl2:(NSString *)strURl valueInt:(int )value{ CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];///横向移动 animation.toValue = [NSNumber numberWithInt:value]; animation.duration = .5; animation.removedOnCompletion = YES;//yes的话,又返回原位置了。 animation.repeatCount = 2; animation.fillMode = kCAFillModeForwards; //抖一抖铃声 //播放音效 NSError *error = nil; NSURL *moveMP3=[NSURL fileURLWithPath:[[NSBundle mainBundle].resourcePath stringByAppendingPathComponent:@"抖一抖铃声.mp3"]]; _player=[[AVAudioPlayer alloc]initWithContentsOfURL:moveMP3 error:&error]; [self.player prepareToPlay]; [self.player play]; AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); AudioServicesPlaySystemSound(1521); [g_window.layer addAnimation:animation forKey:nil]; } -(void)createSoundStrUrl2:(NSString *)strURl messageText:(UITextView *)messageText valueInt:(int )value{ CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];///横向移动 animation.toValue = [NSNumber numberWithInt:value]; animation.duration = .5; animation.removedOnCompletion = YES;//yes的话,又返回原位置了。 animation.repeatCount = 2; animation.fillMode = kCAFillModeForwards; //抖一抖铃声 //播放音效 NSURL *url = [NSURL fileURLWithPath:strURl]; NSError *error = nil; _player=[[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error]; [self.player prepareToPlay]; [self.player play]; // 添加振动 AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); AudioServicesPlaySystemSound(1521); [messageText.inputView.superview.layer addAnimation:animation forKey:nil]; [g_window.layer addAnimation:animation forKey:nil]; } +(void)createSoundStrUrl:(NSString *)strURl valueInt:(int )value{ CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];///横向移动 animation.toValue = [NSNumber numberWithInt:value]; animation.duration = .5; animation.removedOnCompletion = YES;//yes的话,又返回原位置了。 animation.repeatCount = 2; animation.fillMode = kCAFillModeForwards; //抖一抖铃声 //播放音效 SystemSoundID soundID; NSURL *filePath = [NSURL fileURLWithPath:strURl isDirectory:NO]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID); AudioServicesPlaySystemSound(soundID); // 添加振动 AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); AudioServicesPlaySystemSound(1521); [g_window.layer addAnimation:animation forKey:nil]; } +(void)createSoundStrUrl:(NSString *)strURl messageText:(UITextView *)messageText valueInt:(int )value{ CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];///横向移动 animation.toValue = [NSNumber numberWithInt:value]; animation.duration = .5; animation.removedOnCompletion = YES;//yes的话,又返回原位置了。 animation.repeatCount = 2; animation.fillMode = kCAFillModeForwards; //抖一抖铃声 //播放音效 SystemSoundID soundID; NSURL *filePath = [NSURL fileURLWithPath:strURl isDirectory:NO]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID); AudioServicesPlaySystemSound(soundID); // 添加振动 AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); AudioServicesPlaySystemSound(1521); [messageText.inputView.superview.layer addAnimation:animation forKey:nil]; [g_window.layer addAnimation:animation forKey:nil]; } -(void)setStrURL:(NSString *)strURL{ [self.player pause]; [self.player stop]; } @end