Skip to content

Android@10 not playing files served via https://localhost #345

@boedy

Description

@boedy

Bug Report

Problem

Files stored on the device which are accessed through https://localhost should start playing, but don't. Files play fine if accessed directly from the web. A simple Html5 player is able to play the file normally through localhost.

Information

LogCat logs when playing file:

2022-06-01 20:59:30.446 23784-23895/io.cordova.hellocordova V/MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService@771fbf7): Cookies: null
2022-06-01 20:59:30.456 23784-23895/io.cordova.hellocordova W/MediaPlayer: Use of stream types is deprecated for operations other than volume control
2022-06-01 20:59:30.456 23784-23895/io.cordova.hellocordova W/MediaPlayer: See the documentation of setAudioStreamType() for what to use instead with android.media.AudioAttributes to qualify your playback use case
2022-06-01 20:59:30.459 23784-23895/io.cordova.hellocordova W/AudioManager: Use of stream types is deprecated for operations other than volume control
2022-06-01 20:59:30.459 23784-23895/io.cordova.hellocordova W/AudioManager: See the documentation of requestAudioFocus() for what to use instead with android.media.AudioAttributes to qualify your playback use case
2022-06-01 20:59:30.462 23784-23895/io.cordova.hellocordova W/PluginManager: THREAD WARNING: exec() call to Media.startPlayingAudio blocked the main thread for 25ms. Plugin should use CordovaInterface.getThreadPool().
2022-06-01 20:59:30.463 23784-23884/io.cordova.hellocordova V/MediaHTTPService: makeHTTPConnection: CookieManager created: java.net.CookieManager@73fb182
2022-06-01 20:59:30.464 23784-23884/io.cordova.hellocordova V/MediaHTTPService: makeHTTPConnection(android.media.MediaHTTPService@771fbf7): cookieHandler: java.net.CookieManager@73fb182 Cookies: null
2022-06-01 20:59:30.468 23784-23784/io.cordova.hellocordova I/chromium: [INFO:CONSOLE(245)] "1", source: https://localhost/plugins/cordova-plugin-media/www/Media.js (245)
2022-06-01 20:59:30.724 23784-23846/io.cordova.hellocordova D/: PlayerBase::stop() from IPlayer
2022-06-01 20:59:30.724 23784-23846/io.cordova.hellocordova D/AudioTrack: stop() called with 980792 frames delivered
2022-06-01 21:00:00.719 23784-23884/io.cordova.hellocordova E/MediaPlayerNative: error (1, -2147483648)
2022-06-01 21:00:00.720 23784-23895/io.cordova.hellocordova E/MediaPlayer: Error (1,-2147483648)
2022-06-01 21:00:00.720 23784-23895/io.cordova.hellocordova D/AudioPlayer: AudioPlayer.onError(1, -2147483648)
2022-06-01 21:00:00.721 23784-23895/io.cordova.hellocordova V/MediaPlayer: resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
2022-06-01 21:00:00.721 23784-23895/io.cordova.hellocordova V/MediaPlayer: cleanDrmObj: mDrmObj=null mDrmSessionId=null
2022-06-01 21:00:00.729 23784-23784/io.cordova.hellocordova I/chromium: [INFO:CONSOLE(261)] "[object Object]", source: https://localhost/plugins/cordova-plugin-media/www/Media.js (261)

Notice the error:

2022-06-01 21:00:00.719 23784-23884/io.cordova.hellocordova E/MediaPlayerNative: error (1, -2147483648)
2022-06-01 21:00:00.720 23784-23895/io.cordova.hellocordova E/MediaPlayer: Error (1,-2147483648)

Command or Code

Some code snippets that can be run in chrome console when inspecting device

Download sample wav file

(() => {
  const fileTransfer = new FileTransfer();
  const TIMEOUT_INTERVAL = 30 * 1000;
  const filePath = window.cordova.file.dataDirectory + "test.wav";
  
  fileTransfer.download(
    "https://github.com/prof3ssorSt3v3/media-sample-files/blob/master/jimmy-coffee.wav?raw=true",
    filePath,
    file => console.log(file.toURL()),
    error => console.error(error)
  );
})()
// returns: https://localhost/__cdvfile_files__/test.wav

NOT WORKING: Play file locally with cordova-plugin-media (This is the bug)

source = 'http://localhost/__cdvfile_files__/test.wav';
track = new Media(source, null, console.error, console.log);
track.play();

WORKING: Play file remotely with cordova-plugin-media

source = 'https://github.com/prof3ssorSt3v3/media-sample-files/blob/master/jimmy-coffee.wav?raw=true';
track = new Media(source, null, console.error, console.log);
track.play();

WORKING: Play file locally with html5

sound = new Audio("http://localhost/__cdvfile_files__/test.wav");
sound.play();

Environment, Platform, Device

Device: Android 8.1 (API 27)

Version information

Cordova CLI: 11.0.0
Cordova Platforms: android 10.1.2
Cordova Plugins:

  • cordova-plugin-file-transfer 2.0.0-dev "File Transfer"
  • cordova-plugin-file 7.0.0 "File"
  • cordova-plugin-media 6.0.0 "Media"

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions