UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Video Player inside List SwiftUI iOS 16 - controls not displayed

Forums > SwiftUI

@Hell  

I caught a strange situation. In iOS 16, the controls for the video player are not shown if the video player is placed inside the list.

VStack{
    List(0..<2) { i in
        VStack{
            let vp = AVPlayer(url: videoUrl)

            VideoPlayer(player: vp)
                .frame(maxWidth: .infinity, idealHeight: 320)
                .padding(.horizontal, -20)
                .onDisappear{vp.pause()}
        }
    }
}

I can't figure out how to fix it

2      

Eugene appears to want more than one VideoPlayer showing in a single view. Perhaps his code has been simplified, but I am not sure why he has an inner VStack?

I tried this test code without using List.

import SwiftUI
import AVKit

struct MultiPlayerView: View {
    var body: some View {
        VStack {
            // Ready, Player One.
            VideoPlayer(player: AVPlayer(url:  URL(string: "https://bit.ly/swswift")!))
                .frame(height: 400)
            // Player Two has entered the game.
            VideoPlayer(player: AVPlayer(url:  URL(string: "https://bit.ly/swswift")!))
                .frame(height: 400)
        }
        .padding()
    }
}

This works fine! It displays two video players stacked one atop the other.

I can click on a video and it displays the video controls. You can even play both videos at the same time, from different starting points.

For fun, remove the list and stack two of your views in a VStack. Do you get different results?

2      

Then I tried this code:

struct MultiPlayerView: View {
    var body: some View {
        VStack {
            List(0..<2) { _ in
                VideoPlayer(player: AVPlayer(url:  URL(string: "https://bit.ly/swswift")!))
                    .frame(height: 300)
            }
        }
        .padding()
    }
}

I see the issue! While this view struct has two players in it, neither has video controls when you tap either video.

This confirms your problem. But I have no solution other than what I tried above.

2      

@Hell  

@Obelix

Even if the video player is alone inside the list the problem is the same - the controls are not displayed.

In iOS 15.6.1 this code works fine as it should.

3      

@LilaQ  

Did you find a solution to this issue? I'm having the same issue with mutiple players, which is really annoying - I have no clue currently on how to fix this.

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.