خرید بک لینک

Vote count: 0

This is my first steps in Swift (i usually use c#, ASP.NET) and I want to play stream audio from the inteet. I wrote code that plays stream but it don't have any buffer so if signal is weak application stop playing audio. This is my code:

import UIKit
import AVFoundation
import MediaPlayer
import AudioToolbox

class ViewController: UIViewController {

var playerItem:AVPlayerItem?
var player:AVPlayer?

@IBOutlet weak var PlayButton: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()

    var buffer = AVAudioBuffer ()
    let url = NSURL (string: "http://radio.afera.com.pl/afera64.aac")
    playerItem = AVPlayerItem(URL: url!)
    player = AVPlayer(playerItem: playerItem!)

}

override func didReceiveMemoryWaing() {
    super.didReceiveMemoryWaing()
    // Dispose of any resources that can be recreated.
}

@IBAction func PlayButtonTapped(sender: AnyObject)
{
    if ((player!.rate != 0) && (player!.error == nil))
    {
        player!.pause()
        PlayButton.setImage(UIImage(named:"Play"), forState: UIControlState.Normal)
    }
    else
    {
        player!.play()
        PlayButton.setImage(UIImage(named:"Stop"), forState:UIControlState.Normal)
    }
}
}

I have no idea how to buffer this stream. I searched apple documentation but can't find anything in swift. I find something like AVAudioBuffer but I don't know how to use it, and if its correct to resolve this problem. Can somebody help me? P.S. C# have documentation on MSDN, is something similar on Apple in case of Swift?

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 28 فروردين 1395 ساعت: 20:15

صفحه بندی