JXStartSoundView.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // JXStartSoundView.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/6/12.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXStartSoundView.h"
  9. @interface JXStartSoundView()
  10. @end
  11. @implementation JXStartSoundView
  12. -(instancetype)initWithFrame:(CGRect)frame{
  13. if (self=[super initWithFrame:frame]) {
  14. }
  15. return self;
  16. }
  17. -(void)createSoundStrUrl2:(NSString *)strURl valueInt:(int )value{
  18. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];///横向移动
  19. animation.toValue = [NSNumber numberWithInt:value];
  20. animation.duration = .5;
  21. animation.removedOnCompletion = YES;//yes的话,又返回原位置了。
  22. animation.repeatCount = 2;
  23. animation.fillMode = kCAFillModeForwards;
  24. //抖一抖铃声
  25. //播放音效
  26. NSError *error = nil;
  27. NSURL *moveMP3=[NSURL fileURLWithPath:[[NSBundle mainBundle].resourcePath stringByAppendingPathComponent:@"抖一抖铃声.mp3"]];
  28. _player=[[AVAudioPlayer alloc]initWithContentsOfURL:moveMP3 error:&error];
  29. [self.player prepareToPlay];
  30. [self.player play];
  31. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
  32. AudioServicesPlaySystemSound(1521);
  33. [g_window.layer addAnimation:animation forKey:nil];
  34. }
  35. -(void)createSoundStrUrl2:(NSString *)strURl messageText:(UITextView *)messageText valueInt:(int )value{
  36. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];///横向移动
  37. animation.toValue = [NSNumber numberWithInt:value];
  38. animation.duration = .5;
  39. animation.removedOnCompletion = YES;//yes的话,又返回原位置了。
  40. animation.repeatCount = 2;
  41. animation.fillMode = kCAFillModeForwards;
  42. //抖一抖铃声
  43. //播放音效
  44. NSURL *url = [NSURL fileURLWithPath:strURl];
  45. NSError *error = nil;
  46. _player=[[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
  47. [self.player prepareToPlay];
  48. [self.player play];
  49. // 添加振动
  50. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
  51. AudioServicesPlaySystemSound(1521);
  52. [messageText.inputView.superview.layer addAnimation:animation forKey:nil];
  53. [g_window.layer addAnimation:animation forKey:nil];
  54. }
  55. +(void)createSoundStrUrl:(NSString *)strURl valueInt:(int )value{
  56. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];///横向移动
  57. animation.toValue = [NSNumber numberWithInt:value];
  58. animation.duration = .5;
  59. animation.removedOnCompletion = YES;//yes的话,又返回原位置了。
  60. animation.repeatCount = 2;
  61. animation.fillMode = kCAFillModeForwards;
  62. //抖一抖铃声
  63. //播放音效
  64. SystemSoundID soundID;
  65. NSURL *filePath = [NSURL fileURLWithPath:strURl isDirectory:NO];
  66. AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
  67. AudioServicesPlaySystemSound(soundID);
  68. // 添加振动
  69. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
  70. AudioServicesPlaySystemSound(1521);
  71. [g_window.layer addAnimation:animation forKey:nil];
  72. }
  73. +(void)createSoundStrUrl:(NSString *)strURl messageText:(UITextView *)messageText valueInt:(int )value{
  74. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];///横向移动
  75. animation.toValue = [NSNumber numberWithInt:value];
  76. animation.duration = .5;
  77. animation.removedOnCompletion = YES;//yes的话,又返回原位置了。
  78. animation.repeatCount = 2;
  79. animation.fillMode = kCAFillModeForwards;
  80. //抖一抖铃声
  81. //播放音效
  82. SystemSoundID soundID;
  83. NSURL *filePath = [NSURL fileURLWithPath:strURl isDirectory:NO];
  84. AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
  85. AudioServicesPlaySystemSound(soundID);
  86. // 添加振动
  87. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
  88. AudioServicesPlaySystemSound(1521);
  89. [messageText.inputView.superview.layer addAnimation:animation forKey:nil];
  90. [g_window.layer addAnimation:animation forKey:nil];
  91. }
  92. -(void)setStrURL:(NSString *)strURL{
  93. [self.player pause];
  94. [self.player stop];
  95. }
  96. @end