Skip to content

Can't play mp3 - No such file / Failed to connect to localhost #401

@nbruley

Description

@nbruley

Bug Report

Problem

I cannot play mp3 files with the plugin apart from those on my online server.

What is expected to happen?

Play mp3 file. I believe this worked a long time ago but no longer works now...

What does actually happen?

Get error:

/storage/emulated/0/Android/data/com.hablamedecristo.himnario2/files/test.mp3: open failed: ENOENT (No such file or directory)

Note: when trying to access an mp3 file with cordova.file.applicationStorageDirectory or https://localhost/test.mp3, I get the error "java.net.ConnectException: Failed to connect to localhost/127.0.0.1:443"

Information

Command or Code

I have test.mp3 saved in the android/platform_www directory. I also can download to cordova.file.applicationStorageDirectory via the cordova-plugin-file-transfer plugin.

function playDownloadedAudio (fileTransferWebUrl, thisElement) {
	my_media = new Media("test.mp3",
		function () //success;
		{ }, 
		function (error) //error
		{ 
			alertOK(translate('Error in playback. Please contact support. \n Code: ','text') + error.code + '\n '+translate('Message:','text')+' '+error.message + '\n');
			playing = false;
		}
	);
	my_media.play();
}

config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.hablamedecristo.himnario2" version="6.9.0" versionCode="77" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>X</name>
    <description>
        X
    </description>
    <author email="X" href="X">
        X
    </author>
    <content src="index.html" />
    <preference name="android-installLocation" value="preferExternal" />
    <preference name="AndroidPersistentFileLocation" value="Compatibility" /> <!-- use "Internal" instead of "Compatibility" for new apps -->
    <preference name="android-targetSdkVersion" value="34" />
    <preference name="android-compileSdkVersion" value="34" />
    <preference name="android-minSdkVersion" value="23" />
    <preference name="AndroidGradlePluginVersion" value="8.5.1" />
    <preference name="loadUrlTimeoutValue" value="700000" />
	<preference name="scheme" value="https" />
	<preference name="hostname" value="localhost" />
    <plugin name="cordova-plugin-media" spec="7.0.0" />
    <plugin name="cordova-plugin-insomnia" />
    <plugin name="cordova-plugin-file" />
    <plugin name="cordova-plugin-email-composer" />
    <!--<plugin name="cordova-plugin-wkwebview-file-xhr" spec="3.1.1" />-->
    <plugin name="cordova-plugin-file-transfer" />
    <icon src="icon.png" />
    <allow-navigation href="*" />
    <access origin="*" />
    <access origin="file:///*" />
    <access origin="cdvfile://*" />
    <allow-intent href="file:///*" />
    <allow-intent href="cdvfile://*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="mailto:*" />
    
    <!-- not sure if these are needed  https://developer.android.com/training/data-storage/shared/media#kotlin -->
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" />
    
    <platform name="android">
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:usesCleartextTraffic="true" />
        </edit-config>
        <allow-intent href="market:*" />
        <preference name="FadeSplashScreenDuration" value="0"/>
        <preference name="SplashScreenDelay" value="0" />
        <preference name="AndroidWindowSplashScreenBackground" value="#9D9D9C" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

Content Security Policy

<meta http-equiv="Content-Security-Policy" content="default-src * data: gap: cdvfile: http://mysite.com http://mysite2.com http://mysite3.com 'unsafe-eval'; script-src 'self' 'unsafe-inline' https://www.google-analytics.com https://www.googletagmanager.com; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' https://www.googletagmanager.com data:">

Environment, Platform, Device

Android Target SDK = 34
Galaxy Tab A7, Android 12

Version information

Cordova version 12.0.0
cordova-media-plugin version 7.0.0
cordova-plugin-file version 8.1.0
cordova-plugin-file-transfer version 2.0.0
Android Studio Koala 2024.1.1 Patch 2

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions