BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

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

   

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?

   

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.

   

@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.

1      

@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.

   

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

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

Reply to this topic…

You need to create an account or log in to reply.

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.