0

I'm new to IOS development , please i need guidelines or code example on how i can play video using VLCMediaPlayer in SwiftUI

my current code :

import SwiftUI
import MobileVLCKit
import UIKit

struct PlayerView: View {
    
    var videoURL : String
    
    let vlcMediaPlayer = VLCMediaPlayer()
    
    struct VideoView: View {
        var body: some View {
            HStack {
            }.frame(
                width: 100, height: 100, alignment: .center
            )
        }
    }
    
    var body: some View {
        VideoView()
            .onAppear(perform: {
                let url = URL(string: videoURL)!
                print("url",url)
                vlcMediaPlayer.media = VLCMedia(url: url)
                vlcMediaPlayer.drawable = VideoView.self
                vlcMediaPlayer.play()
            })
    }
}

LOG :

decode_slice_header error
[h264 @ 0x7fc54982a000] no frame!

Ps : I can hear the video sound but nothing displayed

  • i'm not sure about my code , i may need to use UIViewRepresentable ? Please send me some references on this can be done – ilies oldm Jan 17 '22 at 12:40
  • Maybe this can help you: https://stackoverflow.com/questions/59806850/vlckit-with-swiftui vlcMediaPlayer.drawable needs a UIView. So you have to wrap it with UIViewRepresentable to use it in swiftUI – Stefan Wieland Jan 17 '22 at 13:24

0 Answers0