Bit of a organized mess. I’m protecting my mp3/ogg files from direct access by serving them through a PHP file. I was having some big issues with serving audio through PHP on mobile devices so I installed Mobile_Detect so I could conditionally serve the direct audio url to mobile users and the PHP url to desktop users. I created shortcodes in functions.php

include_once( get_stylesheet_directory() . '/Mobile_Detect.php');


//ISMOBILE SHORTCODE
add_shortcode( 'ismobile', 'ismobile_shortcode' );
function ismobile_shortcode( $atts, $content = null ) {
$detect = new Mobile_Detect();
if( $detect->isMobile() ) {
return do_shortcode($content);
} else {
return '';}
}

//ISNOTMOBILE SHORTCODE
add_shortcode( 'isnotmobile', 'isnotmobile_shortcode' );
function isnotmobile_shortcode( $atts, $content = null ) {
$detect = new Mobile_Detect();
if( !$detect->isMobile() ) {
return do_shortcode($content);
} else {
return '';}
}

Now when I have an audio player in a post I make 2 instances of it wrapped in each shortcode. Mobile users see the audio player that links to the direct audio url, desktop users see the one linked to the PHP script.

Everything works great except for Safari desktop browser. The audio player won’t seek and the end time shows NaN:NaN. From Googling the issue, it seems this has been a problem since 2010 with Safari and serving audio through PHP.

I figured if I could detect the Safari desktop browser I can include it in my “ismobile” shortcode so the real audio link gets sent to Safari desktop users. Make sense?

I found this http://stackoverflow.com/a/9851769/1131465 but I don’t know how to implement it for my specific case.

Read more here: Detect Safari desktop browser and include the detection in a shortcode


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: