问题
I'm creating a project which requires the user to be able to set a sound to play at a specific time and I'm currently doing that with local notification. I would like to change that to use AVAudioPlayer
, and I was wondering, what would be the best approach?
The objects I've got at the moment are a NSDatePicker
and a stringFromDate
string. My aim is to create an alarm so that the user can set a time using the NSDatePicker
and at that time the sound will go off.
回答1:
Please use Global variable or Class variable to play the alarm.
@property AVAudioPlayer * player;
... ...
_player = [AVAudioPlayer alloc]...
[_player play];
It'll works fine for your project.
来源:https://stackoverflow.com/questions/32628729/add-sound-to-play-at-time-from-nsdatepicker