如您所见,我正在流式传输音频广播。但是当我按下主页按钮并退出应用程序时,流媒体播放停止,或者我听不到声音。如何继续在后台流式传输并从锁定屏幕收听?
ViewController.Swift
import UIKit
import AVFoundation
import MediaPlayer
import GoogleMobileAds
class ViewController: UIViewController, GADInterstitialDelegate {
@IBOutlet weak var exitMapButton: UIButton!
@IBOutlet weak var radarMap: UIWebView!
var interstitial: GADInterstitial!
func createAndLoadInterstitial() -> GADInterstitial {
var interstitial = GADInterstitial(adUnitID: "ca-app-pub-5378899862041789/2782958552")
interstitial.delegate = self
interstitial.loadRequest(GADRequest())
return interstitial
}
func getAd(){
if (self.interstitial.isReady)
{
self.interstitial.presentFromRootViewController(self)
self.interstitial = self.createAndLoadInterstitial()
}
}
@IBOutlet weak var ataturkButton: UIButton!
@IBOutlet weak var sabihaButton: UIButton!
@IBOutlet weak var esenbogaButton: UIButton!
@IBOutlet weak var weatherButton: UIButton!
@IBOutlet weak var statusLabel: UILabel!
@IBOutlet weak var playButton: UIButton!
@IBOutlet weak var webViewButton: UIButton!
var googleBannerView: GADBannerView!
override func viewDidLoad() {
super.viewDidLoad()
}
class PlayerAv {
var audioLink: String?
var player: AVPlayer
init(link: String) {
self.audioLink = link
self.player = AVPlayer(URL: NSURL(string: link))
}
}
var myPlayer = PlayerAv(link: "http://www.liveatc.net/play/ltba.pls")
var setTowerState = ""
@IBAction func sliderValueChanged(sender: UISlider) {
var currentValue = Float(sender.value)
println(currentValue)
myPlayer.player.volume = currentValue
}
holdtom
温温酱