【问题标题】:How to use the AVAudioPlayer header?如何使用 AVAudioPlayer 标头?
【发布时间】:2015-04-29 06:19:07
【问题描述】:

我想用 AVAudioPlayer 播放声音文件,但我的调整让我进入了安全模式。

这是我的代码:

#import <SpringBoard/SpringBoard.h>
#import <AVFoundation/AVAudioPlayer.h>

%hook SpringBoard

- (void)applicationDidFinishLaunching:(id)application {

NSString *settingsPath = @"/var/mobile/Library/Preferences/com.ziph0n.vibrateonstart.plist";

NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];

BOOL enabled = [[prefs objectForKey:@"enabled"] boolValue];

BOOL sound = [[prefs objectForKey:@"sound"] boolValue];

if (enabled) {

    if (sound) {

    %orig;

    SystemSoundID mBeep;

    NSString* path = [[NSBundle mainBundle] pathForResource:@"beep-beep" ofType:@"caf"];;
    NSURL* url = [NSURL fileURLWithPath:path]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &mBeep);

    AudioServicesPlaySystemSound(mBeep);

    }

  }

}

%end

我的音频文件在 Ressources 文件夹中

【问题讨论】:

    标签: ios objective-c avfoundation avaudioplayer cydia-substrate


    【解决方案1】:
    // Import in your header file
    // #import <AVFoundation/AVAudioPlayer.h>
    
    @interface ViewController ()
    @end
    
    @implementation ViewController {
        AVAudioPlayer *beepSound;
    }
    
    -(void)viewDidLoad {
        [super viewDidLoad];
    
        // Get file path
        NSString *beepSoundFile = [[NSBundle mainBundle] pathForResource:@"beep-beep" ofType:@"caf"];
        // Create sound
        beepSound = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:beepSoundFile] error:NULL];
        // Set the volume
        beepSound.volume = 1.0;
        // Load the sound so no lag when we want to play it
        [beepSound prepareToPlay];
    }
    

    使用声音:

    // This will play the sound
    [beepSound play];
    
    // This will stop the sound
    [beepSound stop];
    
    // Restarts the sound at the beginning. Good for long sound files that you're going to use again
    beepSound.currentTime = 0;
    
    // Plays the sound in a loop infinitely
    beepSound.numberOfLoops = -1;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-12
      • 2020-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多