但是现在,如果播放器使用的是头戴式耳机,我只想在右耳或左耳手机中播放一定的声音.
这可能使用AVFoundation吗?
import UIKitimport AVFoundationclass VIEwController: UIVIEwController { overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() // Do any additional setup after loading the vIEw,typically from a nib. testSound() } var audioPlayer = AVAudioPlayer() let alertSound = NSURL(fileURLWithPath: Bundle.main.path(forResource: "CheckoutScannerBeep",ofType: "mp3")!) // If sound not in an assest //let alertSound = NSDataAsset(name: "CheckoutScannerBeep") // If sound is in an Asset func testSound(){ do { // audioPlayer = try AVAudioPlayer(data: (alertSound!.data),fileTypeHint: AVfileTypeMPEGLayer3) //If in asset audioPlayer = try AVAudioPlayer(contentsOf: alertSound as URL) //If not in asset audioPlayer.pan = -1.0 //left headphone //audioPlayer.pan = 1.0 // right headphone audioPlayer.preparetoPlay() // make sure to add this line so audio will play audioPlayer.play() } catch { print("error") } }}总结
以上是内存溢出为你收集整理的ios – 使用AVFoundation有没有办法在swift 2.0中只用耳机的一只耳朵播放声音?全部内容,希望文章能够帮你解决ios – 使用AVFoundation有没有办法在swift 2.0中只用耳机的一只耳朵播放声音?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)