Simple VideoPlayer not working

I am running into serious issues when using the new VideoPlayer or any kind of AVPlayer in Xcode 12 beta 4. On the simulator and on my physical device (both running iOS 14 beta 4), the VideoPlayer stays black. Even running a different app that uses AVPlayer with a UIViewControllerRepresentable results in the AVPlayer not working.

Code Block swift
import SwiftUI
import AVKit
@main
struct SerienStreamApp: App {
    let player = AVPlayer(url: URL(string: "https://www.radiantmediaplayer.com/media/big-buck-bunny-360p.mp4")!)
    var body: some Scene {
        WindowGroup {
            VideoPlayer(player: player)
        }
    }
}

The error I get:

Code Block
2020-08-12 14:32:20.260745+0200 SerienStream[11426:2122834] libMobileGestalt MobileGestaltCache.c:166: Cache loaded with 4527 pre-cached in CacheData and 47 items in CacheExtra.
2020-08-12 14:32:20.336493+0200 SerienStream[11426:2122544] <CATransformLayer: 0x2812101a0> - changing property masksToBounds in transform-only layer, will have no effect
2020-08-12 14:32:20.336776+0200 SerienStream[11426:2122544] <CATransformLayer: 0x28120eb60> - changing property masksToBounds in transform-only layer, will have no effect
2020-08-12 14:32:20.339250+0200 SerienStream[11426:2122544] <CATransformLayer: 0x281210e00> - changing property masksToBounds in transform-only layer, will have no effect
2020-08-12 14:32:20.353454+0200 SerienStream[11426:2122544] <CATransformLayer: 0x281275ca0> - changing property masksToBounds in transform-only layer, will have no effect
2020-08-12 14:32:20.354109+0200 SerienStream[11426:2122544] <CATransformLayer: 0x281276340> - changing property masksToBounds in transform-only layer, will have no effect
2020-08-12 14:32:20.373421+0200 SerienStream[11426:2122544] <CATransformLayer: 0x281210e00> - changing property allowsGroupBlending in transform-only layer, will have no effect
2020-08-12 14:32:20.373483+0200 SerienStream[11426:2122544] <CATransformLayer: 0x281275ca0> - changing property allowsGroupBlending in transform-only layer, will have no effect
2020-08-12 14:32:20.419000+0200 SerienStream[11426:2122826] Metal API Validation Enabled
2020-08-12 14:32:20.514484+0200 SerienStream[11426:2122544] [] [14:32:20.514] FigSubtitleSampleCreateFromPropertyList signalled err=50 (kFigCFBadPropertyListErr) (NULL or bad plist) at /Library/Caches/com.apple.xbs/Sources/EmbeddedCoreMedia/EmbeddedCoreMedia-2747.2.1.1/Prototypes/ClosedCaptions/FigCaptionCommand.c:792


I'm getting the same thing. No issue on Xcode 11.

FigSubtitleSampleCreateFromPropertyList signalled err=50 (kFigCFBadPropertyListErr) (NULL or bad plist) at /Library/Caches/com.apple.xbs/Sources/EmbeddedCoreMedia_Sim/EmbeddedCoreMedia-2747.2.1.1/Prototypes/ClosedCaptions/FigCaptionCommand.c:792
I have the same issue occuring when trying to load a video from local storage using a file path URL. The first frame of the video shows up but the videoplayer doesn't recognize any interaction. I had this issue on iPadOS 14 beta
Any updates here? Having the same issue

Code Block struct CameraConfirmationView: View {
  let videoFileURL: URL
  var body: some View {
    /// - TODO: Change fixed frame to use Geometry Reader
    VStack {
      VideoPlayer(player: AVPlayer(url: videoFileURL))
      Text("Hello World")
    }
  }
}


Error:

Code Block 2020-10-02 16:41:55.263113-0700 test[1300:439513] <CATransformLayer: 0x2807749e0> - changing property masksToBounds in transform-only layer, will have no effect
2020-10-02 16:41:55.263441-0700 test[1300:439513] <CATransformLayer: 0x280774cc0> - changing property masksToBounds in transform-only layer, will have no effect
2020-10-02 16:41:55.264632-0700 test[1300:439513] <CATransformLayer: 0x280775a60> - changing property masksToBounds in transform-only layer, will have no effect
2020-10-02 16:41:55.413553-0700 test[1300:439513] <CATransformLayer: 0x28074cbc0> - changing property masksToBounds in transform-only layer, will have no effect
2020-10-02 16:41:55.414150-0700 test[1300:439513] <CATransformLayer: 0x28074d100> - changing property masksToBounds in transform-only layer, will have no effect
2020-10-02 16:41:55.431251-0700 test[1300:439513] <CATransformLayer: 0x280775a60> - changing property allowsGroupBlending in transform-only layer, will have no effect
2020-10-02 16:41:55.431302-0700 test[1300:439513] <CATransformLayer: 0x28074cbc0> - changing property allowsGroupBlending in transform-only layer, will have no effect


I am able to reproduce this issue on iOS 14.0.1 and XCode 12.
I'm seeing a similar issue with AVPlayer as well. Although, in my case when using an iOS 14 simulator the video images are displayed. Below describes what I've found. I filed an Apple bug report on this issue (FB8780527).

Audio is heard, rate state is working, and video info is available, but the video images are not showing during playback on some iOS/iPadOS 14 devices.
  • This issue is limited to iOS/iPadOS 14+. The issue does not occur on iOS 13 or lower.

  • It is only reproducible on specific devices (like the iPad Pro 12.9" and iPhone 11 Pro), but not on others (like the iPhone SE and iPhone 6s).

  • Not all videos have a problem even on the same device, same app and account.

  • The videos with the problem work elsewhere, such as on a Mac after having pulled the video file from the device, or as stated previously on an iPhone SE with iOS 14.0.1 in the app for the same video, implying there is nothing wrong with the videos.

  • When running the Xcode 12.0.1 debugger for the app debug configuration there are no errors being output by the Apple AVFoundation framework, or others, when loading, starting and playing the video.

  • When this issue occurs, the PIP functionality doesn’t work. i.e.: tapping the PIP button does nothing

From adding some NSLogs in my observeValueForKeyPath:ofObject:change:context: method when the AVPlayerItemStatus changes to AVPlayerItemsStausReadyToPlay the AVPlayerItem.presentationSize and AVPlayerLayer.videoRect are at this point CGSizeZero, whereas the AVPlayerLayer.bounds.size is non-zero. e.g.: (640, 306)
I have the same issue. Just showed up in a production app. Does this have something to do with NSAppTransportSecurity?

Code Block 2020-10-12 13:56:42.547326-0700 VideoTest[13260:444996] [] [13:56:42.547] -[FigHTTPRequestSessionDataDelegate URLSession:dataTask:didReceiveResponse:completionHandler:] signalled err=-12939 (kFigHTTPRequestError_ServerDoesNotSupportByteRanges) (no content length/range with byterange request) at /Library/Caches/com.apple.xbs/Sources/EmbeddedCoreMedia_Sim/EmbeddedCoreMedia-2755.24.7/Prototypes/FigHTTP/FigHTTPRequestNSURLSession.m:1907
   2020-10-12 13:56:42.553548-0700 VideoTest[13260:444678] [] [13:56:42.554] FigSubtitleSampleCreateFromPropertyList signalled err=50 (kFigCFBadPropertyListErr) (NULL or bad plist) at /Library/Caches/com.apple.xbs/Sources/EmbeddedCoreMedia_Sim/EmbeddedCoreMedia-2755.24.7/Prototypes/ClosedCaptions/FigCaptionCommand.c:792


I have the same issue. Has anyone resolved?
Same here. Any updates?
I encountered this problem too, I'm using Swift 5 and iOS 14.

What I noticed is that if you start the app in the view that has the VideoPlayer element, it works. But if you load a view that navigates or loads the VideoPlayer view, it won't work. In the example below, I've created a video that goes through all episodes and lists them out in a horizontal scroll.

When the user taps on one of the episodes, it'll open a popover with the video player in it, allowing the user to watch the video. the URL is dynamically generated too so it pulls the id from the episode from the ForEach.

Not sure if this is the best way; but hey it works 😁

Code Block swift
import SwiftUI
import AVKit
struct EpisodeList: View {
    @State private var player: AVPlayer = AVPlayer(url: URL(string: "https://www.example.com/welcome.mp4")!)
    @State private var isActive: Bool = false
    var body: some View {
        ScrollView(.horizontal, showsIndicators: false) {
            HStack {
                ForEach(episodes) { episode in
                    EpisodeItem(episode: episode)
                        .onTapGesture(perform: {
                            player = AVPlayer(url: URL(string: "https://www.example.com/episide_\(episode.id).mp4")!)
                            isActive = true
                        })
                }
            }
        }
        .popover(isPresented: $isActive, content: {
            VideoPlayer(player: player)
                .aspectRatio(contentMode: .fit)
                .onAppear() {
                    player.play()
                }
        })
    }
}
struct EpisodeList_Previews: PreviewProvider {
    static var previews: some View {
        EpisodeList()
    }
}


Hello,

@JamieCarroll answered the question right.

I just dealt with something similar. The main problem in here is that the player property is not marked as @State var. Let me explain in little more words.

Without marking the property @State, SwiftUI knows very little of what is going on with it. It means that when you set the players URL, currentItem or whatever property to the player, SwiftUI doesn't acknowledge it and does nothing (Not triggering view update). I am pretty sure when setting up the playable URL, in the background AVPlayer does lot of stuff that mutates the object.

Simple VideoPlayer not working
 
 
Q