1

I am trying to make an iPhone application where you press a button and it streams a video from my mac to the phone via MAMP. When I hit the button the player shows up however the video does not play and I get this error.

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)'

Here is the full code:

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()
        }
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
pillarman38
  • 47
  • 3
  • 13

1 Answers1

0

The issue is that your URL string is not encoded and hence URL is nil and your function returns from the body of the guard statement.

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
}
Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
  • Thanks Dávid Its at least trying to retrieve the video now but I'm still getting the same error. Could it be something to do with my connection? – pillarman38 Mar 15 '18 at 15:38
  • Those messages appear in the console even if the video is playing fine, so that is most probably not the issue. Can the same video be played from that URL in a browser for instance, do you only have an issue while playing from an `AVPlayer`? – Dávid Pásztor Mar 15 '18 at 15:41
  • When I use the mp4 version of the video it plays fine in the browser. But neither the m3u8 or the mp4 will play on my phone. – pillarman38 Mar 15 '18 at 15:57
  • You are using an `http` connection, did you add the necessary keys to your `Info.plist` file to make iOS allow the unsafe connection? If you don't know how to do it, check [this](https://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http) Q&A. – Dávid Pásztor Mar 15 '18 at 15:58
  • Yes I did that too. – pillarman38 Mar 15 '18 at 16:02
  • What happens if you try connecting to that URL using `URLSession.shared.dataTask`? – Dávid Pásztor Mar 15 '18 at 16:11
  • I'm just trying to help you narrow down your issue. If you tried using a different method, you could pinpoint the issue to your network connection/server or code depending on whether the network request succeeds using `URLSession.dataTask`. – Dávid Pásztor Mar 15 '18 at 17:02
  • Apples documentation code stated here works perfectly and if I put the url within this code inside in my browser I get an immediate download with no page: ' @IBAction func playVideo(_ sender: AnyObject) { guard let url = URL(string: "https://devimages-cdn.apple.com/samplecode/avfoundationMedia/AVFoundationQueuePlayer_HLS2/master.m3u8") else { return }' – pillarman38 Mar 15 '18 at 17:18