提供的资产名称无效:'(null)'

时间:2018-03-15 15:27:07

标签: ios swift http mamp avplayer

我正在尝试创建一个iPhone应用程序,按下按钮,然后通过MAMP将视频从我的mac流式传输到手机。当我按下按钮时播放器显示,但视频无法播放,我收到此错误。

2018-03-15 10:19:30.487597-0500 stream[5956:2522500] CredStore - performQuery - Error copying matching creds.  Error=-25300, query={
    class = inet;
    "m_Limit" = "m_LimitAll";
    "r_Attributes" = 1;
    sync = syna;
}
2018-03-15 10:19:30.644950-0500 stream[5956:2522500] [] <<<< AVOutputDeviceDiscoverySession (FigRouteDiscoverer) >>>> -[AVFigRouteDiscovererOutputDeviceDiscoverySessionImpl outputDeviceDiscoverySessionDidChangeDiscoveryMode:]: Setting device discovery mode to DiscoveryMode_None (client: stream)
2018-03-15 10:19:30.714388-0500 stream[5956:2522500] [framework] CUICatalog: Invalid asset name supplied: '(null)'
2018-03-15 10:19:30.714440-0500 stream[5956:2522500] [framework] CUICatalog: Invalid asset name supplied: '(null)'
2018-03-15 10:19:30.763593-0500 stream[5956:2522500] [] <<<< AVOutputDeviceDiscoverySession (FigRouteDiscoverer) >>>> -[AVFigRouteDiscovererOutputDeviceDiscoverySessionImpl outputDeviceDiscoverySessionDidChangeDiscoveryMode:]: Setting device discovery mode to DiscoveryMode_Presence (client: stream)
2018-03-15 10:19:30.846707-0500 stream[5956:2522500] [framework] CUICatalog: Invalid asset name supplied: '(null)'
2018-03-15 10:19:30.846763-0500 stream[5956:2522500] [framework] CUICatalog: Invalid asset name supplied: '(null)'

以下是完整代码:

import UIKit
import AVKit
import AVFoundation

class ViewController: UIViewController {
    @IBAction func playVideo(_ sender: Any) {
        guard let url = URL(string: "http://host-2:8888/The Serenity Trance Sample Pack (138 bpm Loops, Vocals, Drums, Snares, Presets, and more!).m3u8") else {
            return
        }
        // Create an AVPlayer, passing it the HTTP Live Streaming URL.
        let player = AVPlayer(url: url)

        // Create a new AVPlayerViewController and pass it a reference to the player.
        let controller = AVPlayerViewController()
        controller.player = player

        // Modally present the player and call the player's play() method when complete.
        present(controller, animated: true) {
            player.play()
        }
    }
}

1 个答案:

答案 0 :(得分:0)

问题是您的网址字符串未编码,因此URLnil,您的函数会从guard语句的正文返回。

guard let encodedUrlString = "http://host-2:8888/The Serenity Trance Sample Pack (138 bpm Loops, Vocals, Drums, Snares, Presets, and more!).m3u8".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: encodedUrlString) else {     
    print("Invalid URL")
    return
}