Unable to show video from HCVimeoVideoExtractor via AVPlayer

24 Views Asked by At

I am having trouble using HCVimeoVideoExtractor, to take a url from vimeo and run it through AVplayer to play it in the app. However i get this error when i try to show the video:

maths[63530:1135587] [connection] nw_proxy_resolver_create_parsed_array [C1.1.1 proxy pac] Evaluation error: NSURLErrorDomain: -1003

I have tried other video links, in the code below it's just a generic one found on vimeos feed so it should work. but it throws the error:

struct VideoDetailView: View { let videoViewText: String let paperType: PaperType

@State private var vimeoPlayer: AVPlayer?
@State private var playerController: AVPlayerViewController?

var body: some View {
    ScrollView {
        VStack(spacing: 16) {
            Text("Progress log for \(videoViewText) - \(paperType == .paper1 ? "Paper 1" : "Paper 2")")
                .font(.headline)
                .padding()
            
            LazyVStack(spacing: 5) {
                ForEach(1...10, id: \.self) { index in
                    Button(action: {
                        // Handle the action for each cell button
                        print("\(videoViewText) \(paperType == .paper1 ? "Paper 1" : "Paper 2") Cell \(index) tapped")
                        
                        // Check for Paper 1, cell 1, year 2023
                        if paperType == .paper1 && index == 1 && videoViewText == "2023" {
                            fetchVimeoPlayer()
                        }
                    }) {
                        PaperButton(label: "\(index)")
                    }
                }
            }
            .padding()
            
            if let player = vimeoPlayer {
                // Display the Vimeo video player
                VideoPlayer(player: player)
                    .frame(width: 300, height: 200) // Adjust the frame size as needed
                    .padding()
            }
        }
        .navigationBarTitle("Solutions")
        .onAppear {
            playerController = AVPlayerViewController()
        }
    }
}

private func fetchVimeoPlayer() {
    guard let vimeoURL = URL(string: "https://vimeo.com/867959464") else { return }

    HCVimeoVideoExtractor.fetchVideoURLFrom(url: vimeoURL) { video, error in
        if let video = video {
            // Present the AVPlayerViewController
                if let player = self.vimeoPlayer, let controller = self.playerController {
                    controller.player = player
                    UIApplication.shared.windows.first?.rootViewController?.present(controller, animated: true) {
                        player.play()
                    }
                }
            }
        }
    }
}
0

There are 0 best solutions below