Bug 226889

Summary: [Swift] [iOS 14.5] - Incorrect playback state reported by requestMediaPlaybackState on website first launch
Product: WebKit Reporter: Nishant Bhasin <nbhasin>
Component: MediaAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: eric.carlson, jer.noble, katherine_cheney, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 14   
Hardware: All   
OS: iOS 14   
Attachments:
Description Flags
Screen recording of simulator showing incorrect state reported by requestMediaPlaybackState none

Description Nishant Bhasin 2021-06-10 11:31:27 PDT
Created attachment 431098 [details]
Screen recording of simulator showing incorrect state reported by requestMediaPlaybackState

Hi, I work on Firefox iOS and wanted to try out the following code that allows us to request media playback state. However I always get media state as `playing` on first launch of website.

Steps to reproduce: 
- Open a media website (Ex. youtube, soundcloud) using WKWebView 
- When the website is fully loaded try to run the following code on the same website to get its media state 

Actual result:
- The code will always print playing on first launch even though nothing is playing

Expected result:
- The code should show paused or suspended as there is no media playing on those websites

```
webView.requestMediaPlaybackState({ state in
    switch state {
    case .none:
        print("TAB - none")
    case .paused:
        print("TAB - paused")
    case .playing:
        print("TAB - playing")
    case .suspended:
        print("TAB - suspended")
    @unknown default:
        fatalError()
    }
})
```

API Link: https://trac.webkit.org/browser/webkit/trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.h#L377
Comment 1 Radar WebKit Bug Importer 2021-06-17 11:32:30 PDT
<rdar://problem/79462265>