Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter ros256

    (@ros256)

    Yeah, looks like that is true… I didn’t modify the code that uses the flash plugin, but since you asked… I added a check for the autoplay parameter and referenced the result when generating the code for flash in Firefox and Opera. Try this :

    wp_embed_register_handler( 'html5_audio', '#^https://.+\.(mp3|ogg|wav)$#i', 'wp_embed_handler_html5_audio' );
    
    function wp_embed_handler_html5_audio( $matches, $attr, $url, $rawattr ) {
    	$flash_player = plugins_url('3523697345-audio-player.swf', __FILE__);
    
    	if ($attr{autoplay}=='autoplay') {
    		$autoplay='true';
    	} else {
    		$autoplay='false';
    	}
    
    	if (preg_match('#^https://.+\.mp3$#i', $url) && preg_match('/Firefox/', $_SERVER["HTTP_USER_AGENT"])) {
    		// For religious reasons Firefox does not support MP3 format in HTML5 audio tag, use Flash player instead
    		$embed = sprintf(
    				'<embed type="application/x-shockwave-flash" flashvars="audioUrl=%1$s&autoPlay='.$autoplay.'" src="'.$flash_player.'" width="400" height="27" quality="best"></embed>',
    				esc_attr($matches[0])
    				);
    	} else if (preg_match('#^https://.+\.mp3$#i', $url) && preg_match('/Opera/', $_SERVER["HTTP_USER_AGENT"])) {
    		// Opera also does not support MP3 format in HTML5 audio tag, use Flash player instead
    		$embed = sprintf(
    				'<embed type="application/x-shockwave-flash" flashvars="audioUrl=%1$s&autoPlay='.$autoplay.'" src="'.$flash_player.'" width="400" height="27" quality="best"></embed>',
    				esc_attr($matches[0])
    				);
    	} else if (preg_match('#^https://.+\.ogg$#i', $url) && preg_match('/MSIE/', $_SERVER["HTTP_USER_AGENT"])) {
    		$embed = '[Internet Explorer does not support OGG format]';
    	} else if (preg_match('#^https://.+\.wav$#i', $url) && preg_match('/MSIE/', $_SERVER["HTTP_USER_AGENT"])) {
    		$embed = '[Internet Explorer does not support WAV format]';
    	} else {
    		$embed = sprintf(
    				'<audio controls preload '.$attr{autoplay}.'><source src="%1$s" /><embed type="application/x-shockwave-flash" flashvars="audioUrl=%1$s" src="'.$flash_player.'" width="400" height="27" quality="best"></embed></audio>',
    				esc_attr($matches[0])
    				);
    	}
    
    	$embed = apply_filters( 'oembed_html5_audio', $embed, $matches, $attr, $url, $rawattr );
    	return apply_filters( 'oembed_result', $embed, $url, '' );
    }
Viewing 1 replies (of 1 total)