2015-09-08 68 views
-1

对不起,愚蠢的问题))但我不知道如何在SWIFT中为我的应用程序(游戏)添加背景音乐。当我运行它时,必须播放背景音乐。几年前我在Xcode工作,但现在它改变了(((更新。这是一个废话。我的应用程序没有音乐。在互联网搜索我没有找到答案。大多数答案连接音乐播放,当你推按钮(我并不需要它),我需要在后台播放音乐我的应用程序运行时如何在Xcode 6.4 SWIFT应用程序中添加播放背景音乐?

+0

看到这个链接可能会对你有所帮助http://stackoverflow.com/questions/31422014/play-background-music-in-app –

+0

非常感谢! –

回答

0

使用AVAudioPlayer

let path = NSBundle.mainBundle().pathForResource("mySound", ofType: "mySound") 
let Url = NSURL(fileURLWithPath: soundFilePath!) 
let mediaPlayer = AVAudioPlayer(contentsOfURL: soundFileURL, error: nil) 
player.numberOfLoops = -1 //anything less than 0 cause it to unlimited looping 
player.play() 

进口AvFoundation !!!!

+0

AVFoundation adde d。但是,在ViewController.swift中插入代码的位置?在什么地方粘贴它将是没有错误的? –

+0

这不适用于xCode 7/swift 2 !!! –

相关问题