最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Extend WordPress Audio Widget to accept HLS (.m3u8) URLs

programmeradmin2浏览0评论

I'm working on a new FM radio station website, I was trying to use the default WordPress Audio Widget to play their live audio stream. The problem was that the Insert from URL option doesn't accept .m3u8 URLs.

I've tried to insert the following URL: .m3u8 but it showed the following error:

Looks like this isn’t the correct kind of file. Please link to an audio file instead.

So I tried to save the same URL but with .mp3 extension instead of .m3u8, then tried to change the URL in the wp_options table in the database, but it didn't work, and the whole widget was deleted.

Is there any way to extend the accepted file types of the WordPress Default Audio widget to accept the .m3u8 extension?

NOTE: WordPress uses the www.mediaelementjs in their audio and video players which supports HLS sources by default, so I assume the audio widget can run the .m3u8 URLs if we found a way to extend the accepted file types (currently are: .mp3, .m4a, .ogg, and .wav).

I'm working on a new FM radio station website, I was trying to use the default WordPress Audio Widget to play their live audio stream. The problem was that the Insert from URL option doesn't accept .m3u8 URLs.

I've tried to insert the following URL: https://streamingcdn.alaan.tv/fm/fm/playlist.m3u8 but it showed the following error:

Looks like this isn’t the correct kind of file. Please link to an audio file instead.

So I tried to save the same URL but with .mp3 extension instead of .m3u8, then tried to change the URL in the wp_options table in the database, but it didn't work, and the whole widget was deleted.

Is there any way to extend the accepted file types of the WordPress Default Audio widget to accept the .m3u8 extension?

NOTE: WordPress uses the www.mediaelementjs in their audio and video players which supports HLS sources by default, so I assume the audio widget can run the .m3u8 URLs if we found a way to extend the accepted file types (currently are: .mp3, .m4a, .ogg, and .wav).

Share Improve this question asked Jun 22, 2019 at 12:29 Jaafar AbazidJaafar Abazid 952 silver badges11 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

There is a filter, wp_audio_extensions, that should allow you to add m3u8 to the whitelist of allowed file extensions. Add this code to a child theme's functions.php file, or using a plugin like Code Snippets:

function wpse_341199_allow_m3u8_extension( $exts ) {
    $exts[] = 'm3u8';

    return $exts;
}
add_filter( 'wp_audio_extensions', 'wpse_341199_allow_m3u8_extension' );
发布评论

评论列表(0)

  1. 暂无评论