• Resolved dripstone

    (@dripstone)


    I want to add external mp3 files to the media library by using hooks. Now i am not sure, where to add the code.

    add_filter( ’eml_supported_mime_types’, function( $list ) {
    $list[‘audio/mp3’] = array(
    ‘label’ => ‘MP3 Audio’,
    ‘ext’ => ‘mp3’
    );
    return $list
    } );

    Does the code belong in the functions.php of the theme?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author threadi

    (@threadi)

    If you have a child theme, you can put it in its functions.php. If you don’t have a child theme, use the code snippet plugin or something similar.

    Pay attention to the exact spelling of the code. Here in the forum, the inverted commas are misspelled in your post. I don’t know if this is due to your source for the code or the lack of formatting as a code block in your post. The code should actually look like this:

    add_filter( 'eml_supported_mime_types', function( $list ) {
     $list['audio/mp3'] = array(
      'label' => 'MP3 Audio',
      'ext' => 'mp3'
     );
     return $list
    } );
    Thread Starter dripstone

    (@dripstone)

    Thanks for the quick reply. I have installed the code snippet plugin. Now I get a syntax error when I enter the code.

    Parse Error : syntax error , unexpected ‘}’, expecting ‘;’ on line 7

    Plugin Author threadi

    (@threadi)

    Ah, yes, there is a “;” missing. Corrected:

    add_filter( 'eml_supported_mime_types', function( $list ) {
        $list['audio/mp3'] = array(
            'label' => 'MP3 Audio',
            'ext' => 'mp3'
        );
        return $list;
    } );
    Thread Starter dripstone

    (@dripstone)

    Now the snippet plugin is working. If I now want to load an mp3 file from a Dropbox into the media library, the following error message appears:

    The specified URL https://www.dropbox.com/…………. responds with an invalid content-type text/html; charset=utf-8.

    Plugin Author threadi

    (@threadi)

    This obviously doesn’t work because the URL you entered is an HTML page and not an MP3 file. To do this, dropbox.com would have to provide you with such a direct URL. According to their documentation, this is possible with an additional parameter in the URL: https://help.dropbox.com/de-de/share/force-download

    Thread Starter dripstone

    (@dripstone)

    Unfortunately I haven’t made any progress. In the Dropbox, I used “dl=1” and “raw=1” as query parameters in the link. In both cases I get the error message: The specified URL https://www.dropbox.com/*&raw=1 responds with http-status 302.

    I have tried another puplic folder in another cloud and I get the error: The specified URL https://filedn.eu/.mp3 responds with http-status 404.
    What am I doing wrong?

    Plugin Author threadi

    (@threadi)

    The URLs you are using apparently do not return any importable files. A http-status 404 means the file does not exist.

    You can test it e.g. with https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf – this must work as this importable file is directly accessible.

    For files that you want to import this way, you need exactly such URLs. They must refer directly to the file.

    Thread Starter dripstone

    (@dripstone)

    Now I have found the solution. The content type is not audio/mp3 but audio/mpeg.

    add_filter( ’eml_supported_mime_types’, function( $list ) {
    $list[‘audio/mpeg’] = array(
    ‘label’ => ‘MP3 Audio’,
    ‘ext’ => ‘mp3’
    );
    return $list;
    } );

    Plugin Author threadi

    (@threadi)

    Great if you have found a solution. For me, this points to a faulty content type on the part of the URLs you are using. But it is of course also a solution.

    You are welcome to set the topic to solved once it has been clarified for you.

    Thread Starter dripstone

    (@dripstone)

    The problem with the URL was spaces in the file name. Now everything works great. Thank you for your patience.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Adding MP3 by using hooks’ is closed to new replies.