ios - Playing/Pausing sound in an iPhone app -
is there way stop audio playing here? play/stop kind of thing?
-(ibaction)playsound:(id)sender{ audiotitle = [nsstring stringwithformat:@"audio %@", audiointeger]; cfbundleref mainbundle = cfbundlegetmainbundle(); cfurlref soundfileurlref; soundfileurlref = cfbundlecopyresourceurl(mainbundle, (cfstringref) audiotitle, cfstr ("mp3"), null); uint32 soundid; audioservicescreatesystemsoundid(soundfileurlref, &soundid); audioservicesplaysystemsound(soundid); }
here simple play/pause/stop example using avaudioplayer class.
create playing in viewdidload:
var audiopath = nsbundle.mainbundle().pathforresource("bach1", oftype: "mp3") var error : nserror? = nil player = avaudioplayer(contentsofurl: nsurl(string: audiopath!), error: &error)
inside play button:
player.play()
inside pause button:
player.pause()
inside stop button:
player.stop() player.currenttime = 0;
Comments
Post a Comment