jessesquires / JSQSystemSoundPlayer

A fancy Obj-C wrapper for Cocoa System Sound Services
https://jessesquires.github.io/JSQSystemSoundPlayer/
Other
581 stars 107 forks source link

Play AudioServices predefined sounds? #29

Closed djiangnz closed 8 years ago

djiangnz commented 8 years ago

hi @jessesquires

i try user jsqsystemsoundplayer to play system alert, as http://iphonedevwiki.net/index.php/AudioServices

but it doesn't work.

i tried,

[[JSQSystemSoundPlayer sharedPlayer]  playAlertSoundWithFilename:@"/System/Library/Audio/UISounds/sms-received1" fileExtension:kJSQSystemSoundTypeCAF];

tried

[[JSQSystemSoundPlayer sharedPlayer]  playAlertSoundWithFilename:@"sms-received1" fileExtension:kJSQSystemSoundTypeCAF];

tried

[[JSQSystemSoundPlayer sharedPlayer] preloadSoundWithFilename:@"sms-received1" fileExtension:kJSQSystemSoundTypeCAF];
[[JSQSystemSoundPlayer sharedPlayer]  playAlertSoundWithFilename:@"sms-received1" fileExtension:kJSQSystemSoundTypeCAF];

this repo called system player, so i reckon it should work. thanks for you help

jessesquires commented 8 years ago

Hey @lastObject ! :smile:

Ha, so the "system player" name refers to the framework that this library wraps up — System Sound Services — not to playing actual predefined sounds in AudioServices.

None of your suggestions will work because they are searching [NSBundle mainBundle].

I'm not sure if it's possible to play these predefined sounds on iOS — and it's probably against Apple's guidelines. At least, it probably wouldn't be a good user experience. You should really use this for your own sound effects.

In any case, SystemSoundID is simply a UInt32, so you could probably pass the SoundIDs listed in that wiki page to play them — but this would require access to JSQSystemSoundPlayer private methods.

jessesquires commented 8 years ago

Oh, actually I just tried this and it worked.

If you assign the SoundIDs from the wiki to here, then it works. :tada:

For example:

SystemSoundID soundID = 1000; // new-mail.caf

Maybe this would be cool to support. I've opened #30 to track this.

djiangnz commented 8 years ago

@jessesquires

yes, that is what i want. i ll try, thanks