WordPress.org

Ready to get started?Download WordPress

Forums

Magic Fields 2
html5 audio player? (3 posts)

  1. jeanto
    Member
    Posted 1 year ago #

    Hello again,

    I read on an old update that the audio player would be HTML5 but until now it is still flash.

    Any idea how to go over this issue. I need my read to play mp3 on iphone and I don't want to let go Magic fields...

    http://wordpress.org/extend/plugins/magic-fields-2/

  2. Magenta Cuda
    Member
    Posted 1 year ago #

    If I understand this correctly you just want to emit code for the HTML5 audio player instead of the Flash audio player. I think a simple change to function get_audio() in file mf_front_end.php will do this.

    function alt_get_audio( $field_name, $group_index=1, $field_index=1, $post_id=NULL ){
      global $post;
    
      if(!$post_id){ $post_id = $post->ID; }
      $audio = get($field_name,$group_index,$field_index,$post_id);
    
      if( empty($audio) ) return FALSE;
    
      $mime_type = [
        'mp3' => 'audio/mpeg',
        'wav' => 'audio/wav',
        'ogg' => 'audio/ogg',
      ];
    
      $extension = strtolower( pathinfo( $audio,  PATHINFO_EXTENSION ) );
    
      #error_log( 'alt_get_audio():$_SERVER[\'HTTP_USER_AGENT\']=' . print_r( $_SERVER['HTTP_USER_AGENT'], true ) );
      #error_log( 'alt_get_audio():$extension=' . print_r( $extension, true ) );
    
      # the condition in the following if statement may need adjustment
      if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'iPad;' ) ) {
      #if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Windows ' ) ) { # for testing against Windows
        if ( array_key_exists( $extension, $mime_type ) ) {
          $player = '<audio controls><source src="' . $audio . '" type="' . $mime_type[$extension] .'"></audio>';
        } else {
          'Your browser cannot play ' . $extension . ' audio files.';
        }
      } else {
        $player = stripslashes(trim("\<div style=\'padding-top:3px;\'\>\<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' codebase='\http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\' width=\'95%\' height=\'20\' wmode=\'transparent\' \>\<param name=\'movie\' value=\'".MF_URL."js/singlemp3player.swf?file=".urlencode($audio)."\' wmode=\'transparent\' /\>\<param name=\'quality\' value=\'high\' wmode=\'transparent\' /\>\<embed src=\'".MF_URL."js/singlemp3player.swf?file=".urlencode($audio)."' width=\'50\%\' height=\'20\' quality=\'high\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\' type=\'application/x-shockwave-flash\' wmode=\'transparent\' \>\</embed\>\</object\>\</div\>"));
      }
    
      #error_log( 'alt_get_audio():$player=' . print_r( $player, true ) );
    
      return $player;
    }

    Alternatively, you can include alt_get_audio() in your functions.php and call it in place of get_audio(). N.B. I was not able to test this on an iPad as I don't own one. In particular I am not sure what USER-AGENT string it sends.

  3. jeanto
    Member
    Posted 1 year ago #

    working perfect!!!
    Thanks

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.