ios - 在 Swift 中使用 AVPlayer。 iPhone 上没有错误,但没有声音

标签 ios swift audio avplayer

在 Swift 中使用 AVPlayer。没有错误,但 iPhone 上没有声音。

我是 Swift 新手。我将不胜感激。

这是我的代码:

import UIKit
import AVFoundation

class PlayerViewController: UIViewController {
    // This time, we'll declare avPlayer as an instance variable,
    // which means it exists as long as our view controller exists.
    var avPlayer: AVPlayer!

    override func viewDidLoad() {
        super.viewDidLoad()

        print("Connecting...")

        // If you'd rather not use this sound file,
        // replace the string below with the URL of some other MP3.
        let urlString = "http://live.canstream.co.uk:8000/bangradio.mp3"
        let url = NSURL(string: urlString)!
        avPlayer = AVPlayer(URL: url)

        print("Connected to One Radio!")
        avPlayer.play()
        print("Now playing...")
    }

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

最佳答案

您可以尝试使用 AVPlayerItem(url:"your url"),并设置到 avplayer 中。

关于ios - 在 Swift 中使用 AVPlayer。 iPhone 上没有错误,但没有声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39728451/

相关文章:

ios - 有没有更好的方法来深度复制 UIWebView?

php - 如何使用 AFNetworking 2.0 检查 Wordpress 登录信息?

ios - 恢复购买功能 - Swift

swift - FileManager.default.contentsOfDirectory 在 swift 3 中失败

c++ - 从视频中提取音频为 wav

ios - 如何在 Titanium (iOS) 中计算出设备类型

iphone - 设置 VC.view 出现在父 VC 的 View 中,不适合我

swift - 如何将 [Any] 转换为 NSArray?

java - 如何实时计算音频幅度(android)

c# - 使用 AudioGraph (UWP) 混合波形文件