<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>221413</bug_id>
          
          <creation_ts>2021-02-04 09:12:13 -0800</creation_ts>
          <short_desc>Safari does not execute JavaScript code to play another audio item when playing backgrounded FairPlay content</short_desc>
          <delta_ts>2022-12-16 12:01:25 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Web Audio</component>
          <version>Safari 14</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>iOS 14</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=233257</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Tom Spence">thomass</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>brad</cc>
    
    <cc>cdumez</cc>
    
    <cc>jer.noble</cc>
    
    <cc>supersonicandtails</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>xyeres</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1725649</commentid>
    <comment_count>0</comment_count>
    <who name="Tom Spence">thomass</who>
    <bug_when>2021-02-04 09:12:13 -0800</bug_when>
    <thetext>Hello, we are currently attempting to get Safari to automatically move on to the next audio track when a track ends (by subscribing to the &quot;ended&quot; event of the media element), when the browser is in the background.  We are doing this by executing JavaScript that replaces the src attribute with a new HLS manifest URL. Currently playback terminates at the end of the first track and does not progress to the second.  No error is raised.

The expected behaviour would be that playback continues with the next audio track.

Could you assist?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1726491</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2021-02-07 10:51:23 -0800</bug_when>
    <thetext>Tba kn you for the report! Could you please provide a test case?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1727039</commentid>
    <comment_count>2</comment_count>
    <who name="Tom Spence">thomass</who>
    <bug_when>2021-02-09 07:18:32 -0800</bug_when>
    <thetext>(In reply to Alexey Proskuryakov from comment #1)
&gt; Thank you for the report! Could you please provide a test case?

Reproduction steps
1. Open Safari on an iOS device
2. Go to URL: https://spoti.fi/harmony-doctor
3. Log in with a Spotify user.
4. Start playback on a playlist, album, or other context with multiple tracks.
5. Wait for playback to start
6. Background Safari
7. Wait for the first song to end

Expected outcome
The second song should play

Actual outcome
Playback stop</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1728125</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2021-02-11 09:13:14 -0800</bug_when>
    <thetext>&lt;rdar://problem/74236954&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1867342</commentid>
    <comment_count>4</comment_count>
      <attachid>458973</attachid>
    <who name="Brad Isbell">brad</who>
    <bug_when>2022-05-06 14:17:23 -0700</bug_when>
    <thetext>Created attachment 458973
Demonstrates the bug in iOS Safari

This bug is still an issue, and is also a problem for regular audio files without DRM.

Attached is a page with some script demonstrating the issue.

Observations:

 - The `ended` event does fire and its handlers do run, even when the screen is off.
 - Upon replacing the `src` of the `&lt;audio&gt;` element, it cannot be played via script when the screen is off.
 - The `paused` property value is `false`, `currentTime` is `0` zero.  Audio playback does not occur.
 - The only way to resume playback is to unlock phone, and use a UI element to call `.play()` on the audio element.

This prevents web apps from playing from a playlist of media.  It also seems to be a regression, as this method used to work.  This method is also documented here:  https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/ControllingMediaWithJavaScript/ControllingMediaWithJavaScript.html#//apple_ref/doc/uid/TP40009523-CH3-SW5</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1902640</commentid>
    <comment_count>5</comment_count>
    <who name="Peter Fernandes">supersonicandtails</who>
    <bug_when>2022-10-01 14:16:57 -0700</bug_when>
    <thetext>(In reply to Brad Isbell from comment #4)
&gt; Created attachment 458973 [details]
&gt; Demonstrates the bug in iOS Safari
&gt; 
&gt; This bug is still an issue, and is also a problem for regular audio files
&gt; without DRM.
&gt; 
&gt; Attached is a page with some script demonstrating the issue.
&gt; 
&gt; Observations:
&gt; 
&gt;  - The `ended` event does fire and its handlers do run, even when the screen
&gt; is off.
&gt;  - Upon replacing the `src` of the `&lt;audio&gt;` element, it cannot be played
&gt; via script when the screen is off.
&gt;  - The `paused` property value is `false`, `currentTime` is `0` zero.  Audio
&gt; playback does not occur.
&gt;  - The only way to resume playback is to unlock phone, and use a UI element
&gt; to call `.play()` on the audio element.
&gt; 
&gt; This prevents web apps from playing from a playlist of media.  It also seems
&gt; to be a regression, as this method used to work.  This method is also
&gt; documented here: 
&gt; https://developer.apple.com/library/archive/documentation/AudioVideo/
&gt; Conceptual/Using_HTML5_Audio_Video/ControllingMediaWithJavaScript/
&gt; ControllingMediaWithJavaScript.html#//apple_ref/doc/uid/TP40009523-CH3-SW5

Brad, are you doing any potentially long-running async operations (fetch, etc.) before the next track starts playing? I have this use case working in my own app. Playback of a user playlist works continuously with the Safari browser tab backgrounded on desktop, or PWA backgrounded on iOS.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1920023</commentid>
    <comment_count>6</comment_count>
    <who name="Michael">xyeres</who>
    <bug_when>2022-12-16 12:01:25 -0800</bug_when>
    <thetext>I have been searching for a solution to this for the past 11 months, as Tom stated, all of my attempts to replace a media (&lt;audio&gt;) source sequentially while in the background (or in locked screen) have failed until recently when I  updated iOS. 

The issue appears to have been fixed. I made no code changes to my app and it just began working after updating to iOS 15.7.2 (The fix may have been prior to this particular version however since I was on 15.5x) I&apos;ve tried to look for more information in the release notes but haven&apos;t been able to spot the exact change that resolved this issue. 

Very happy about this fix.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>458973</attachid>
            <date>2022-05-06 14:17:23 -0700</date>
            <delta_ts>2022-05-06 14:17:23 -0700</delta_ts>
            <desc>Demonstrates the bug in iOS Safari</desc>
            <filename>alt-test.html</filename>
            <type>text/html</type>
            <size>1911</size>
            <attacher name="Brad Isbell">brad</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgogIDxoZWFkPgogICAgPG1ldGEgY2hhcnNldD0iVVRGLTgi
IC8+CiAgICA8dGl0bGU+aU9TIFNhZmFyaSBTZXF1ZW50aWFsIE1lZGlhIEJ1ZyBUZXN0PC90aXRs
ZT4KICAgIDxtZXRhIG5hbWU9InZpZXdwb3J0IiBjb250ZW50PSJ3aWR0aD1kZXZpY2Utd2lkdGgs
IGluaXRpYWwtc2NhbGU9MSIgLz4KICAgIDxzY3JpcHQgdHlwZT0ibW9kdWxlIj4KICAgICAgY29u
c3QgdXJscyA9IFsKICAgICAgICAnaHR0cHM6Ly9hcmNoaXZlLm9yZy9kb3dubG9hZC9jZF90aGUt
bmV3LWRlYWxfdGhlLW5ldy1kZWFsL2Rpc2MxLzAxLiUyMFRoZSUyME5ldyUyMERlYWwlMjAtJTIw
QmFjayUyMHRvJTIwdGhlJTIwTWlkZGxlX3NhbXBsZS5tcDMnLAogICAgICAgICdodHRwczovL2Fy
Y2hpdmUub3JnL2Rvd25sb2FkL2NkX3RoZS1uZXctZGVhbF90aGUtbmV3LWRlYWwvZGlzYzEvMDIu
JTIwVGhlJTIwTmV3JTIwRGVhbCUyMC0lMjBSZWNlaXZlcl9zYW1wbGUubXAzJywKICAgICAgICAn
aHR0cHM6Ly9hcmNoaXZl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