HTML5 WordPress Music Player & Settings Page Integration

HTML5 WordPress Music Player & Settings Page Integration

Tutorial Details
  • Program: WordPress
  • Version (if applicable): 3.0
  • Difficulty: Beginner to Intermediate
  • Estimated Completion Time: 1 Hour

Final Product What You'll Be Creating

I will be showing how to integrate an HTML 5 Music Player into WordPress. After that we will be adding a Settings Page ("theme options") so you can allow for easy player customization!

This music player has finally made its way to WP! The design was originally created by Orman Clark after which Saleem from Codebase Hero created a jQuery plugin out of it.

Today I will be taking that plugin and integrating it into WP. I would like to point out that I’m not an advanced WP developer and the code that I will be using is compiled from various tutorials across the web. I would just like to share with everyone how I did it. Also I will not be going into explaining the jQuery plugin code created by Saleem, I can help answer any questions but best thing to do is to just head over to the plugin page and go through the documentation. You may download the source files and customize it to your preference. Well, lets fire away..


Things We Will Do

Hopefully by the end of this tutorial you will be able to:

  • Integrate HTML5 Music Player into WP
  • Create Custom Post Type + Custom Meta Box
  • Create Settings Page for your Music Player

Step 1 Download Source Files

First download the required source files and copy folder named "blank" into your wp-content/themes/ folder where all your themes are located. You will need the files to complete this tutorial!

Your directory should look like this: wp-content/themes/blank.

Ok, from now on we will be working inside your “blank” theme folder.


Step 2 Creating Additional Folders and Files

Go to your downloaded source files folder and copy the playlist folder into your theme folder. The folder contains 3 folder css, images, and js.

Those folders contain all the files and images that came with the HTML5 Music Player and we will not be editing those.

Lets create some more files. Inside playlist folder create 2 files playlist.php and playlist-post-type.php. Now open css folder and create a file playlist-style.css.

Take a look at the folder structure image below to make sure you have all the correct files.


Step 3 Custom Post Type – Playlist

Lets create the post type called playlist. More on custom post types at WP Codex. Open playlist-post-type.php file.

<?php
// Adding Custom Post Type
add_action('init', 'playlist_register');
function playlist_register() {	
		$labels = array(
        'name'					=> _x('Playlist','Music Player','Music Player'),
        'singular_name'		=> _x('Music Player','Music Player', 'Music Player'),
        'add_new'				=> _x('Add New Track', 'Music Listing','Music'),
        'add_new_item'			=> __('Add New Track','Music'),
        'edit_item'			=> __('Edit Track','Music'),
        'new_item'				=> __('New Music Post Item','Music'),
        'view_item'			=> __('View Music Item','Music'),
        'search_items'			=> __('Search Music Items','Music'),
        'not_found'			=> __('Nothing found','Music'),
        'not_found_in_trash'	=> __('Nothing found in Trash','Music'),
        'parent_item_colon'	=> ''
        );
        
        $args = array(
        'labels'				=> $labels,
        'public'				=> true,
        'exclude_from_search'	=> false,
        'show_ui'				=> true,
        'capability_type'		=> 'post',
        'hierarchical'			=> false,
        'rewrite'				=> array( 'with_front' => false ),
        'query_var'			=> false,
        'menu_icon'			=> get_stylesheet_directory_uri() . '/playlist/images/playlist.png',
        'supports'				=> array('title', 'editor', 'thumbnail'),
        );
        register_post_type( 'playlist' , $args );
        }

// Maker sure any other code added to playlist-post-type.php is above this text! The closing php tag needs to be last peice of code in this file!
?>

Pretty basic stuff here, this will create a new post type called Playlist in our admin dashboard menu. For now you won’t be able to see it yet, because we haven’t actually attached it. So for that we need to go back to the main theme directory and open up functions.php file. Add the following.

// DEFINE PATHS
define('OD_PLAYER', TEMPLATEPATH . '/playlist/');	// Playlist Directory

// REQUIRE FILES
require_once(OD_PLAYER . '/playlist-post-type.php');	// Get Custom Post Type : Playlist

Go back to your dashboard and refresh the page, you should now be able to see Playlist in the menu. Click on Playlist and you’ll notice that right now we have the default columns that display the Title and Date. We want to go in and change the columns to something more relevant for our post type. We will add columns for Album Cover, Track Title, and Artist Name. Open up playlist-post-type.php and add this.

//Custom Overview Page
add_action("manage_posts_custom_column", "music_custom_columns"); add_filter("manage_edit-playlist_columns", "my_areas_columns");
function my_areas_columns($columns) { $columns = array( "thumbnail" => "Album Cover", "cb" => "<input type=\"checkbox\" />", "title" => "Track Title", "artist" => "Artist Name" ); return $columns; } function music_custom_columns($column) { global $post; if ("ID" == $column) echo $post->ID; elseif ("artist" == $column) echo get_post_meta(get_the_ID(),'music_artist',true); elseif ("thumbnail" == $column) the_post_thumbnail('album-thumb'); }

That looks much better, don’t you think? Ok, lets add some more stuff to this file. I want to have a custom icon for this post type. If you hit Add New Track you’ll notice that the current icon is just WP default "pin", lets add the headphones icon instead.

// Adding Custom Screen Icons on Edit and Add New Screens
add_action('admin_head', 'plugin_header');
function plugin_header() {
	global $post_type;
    ?>
    <style>
    <?php if (($_GET['post_type'] == 'playlist') || ($post_type == 'playlist')) : ?>
    #icon-edit { background:transparent url('<?php echo get_stylesheet_directory_uri() .'/playlist/images/playlist_large.png';?>') no-repeat; }
    <?php endif; ?>
    </style>
    <?php
    }

I would also like to add custom css to our new post type so lets attach a css file to it, add the following.

//Add Custom CSS to the post
add_action('admin_head', 'tracklist_admin_css');
function tracklist_admin_css() {
	global $post_type; if (($_GET['post_type'] == 'playlist') || ($post_type == 'playlist')) : ?>
	<link rel='stylesheet' type='text/css' href='<?php echo get_stylesheet_directory_uri() .'/playlist/css/playlist-style.css';?>' />
	<?php endif;
}

We will add some styles later, for now lets continue adding things to our post type. The last thing left to add is meta box. Before we do that we need to know what type of inputs we need to add. That’s easy because we already know since we are building upon a "finished" product. HTML5 Music Player contains a file with the following options.

var myPlaylist = [
{
  mp3:'mix/1.mp3',
  oga:'mix/1.ogg',
  title:'Sample',
  artist:'Sample',
  rating:4,
  buy:'#',
  price:'0.99',
  duration:'0:30',
  cover:'mix/1.png'
}
];

One thing I should point out right away is we will not be focusing on the “rating” part of the music player. Ok so from that we can tell that we need the following inputs:

  1. mp3 (meta input)
  2. ogg (meta input)
  3. title (post title)
  4. artist (meta input)
  5. buy (meta input)
  6. price (meta input)
  7. duration (meta input)
  8. cover (featured image)

Lets add meta box with those items. Below code will basically prefill input fields (we will make those after this) if there was something saved in them.

// Adding Custom Meta Information for tracks
	add_action('add_meta_boxes', 'music_add_custom_box');
    function music_add_custom_box() {
    	add_meta_box('track_info', 'Track Information', 'track_box', 'playlist','normal', 'high');
	}
function track_box() {
	$music_mp3 = '';
	if ( isset($_REQUEST['post']) ) {
		$music_mp3 = get_post_meta((int)$_REQUEST['post'],'music_mp3',true);
	}
    
	$music_ogg = '';
	if ( isset($_REQUEST['post']) ) {
    	$music_ogg = get_post_meta((int)$_REQUEST['post'],'music_ogg',true);
    }
    
	$music_artist = '';
	if ( isset($_REQUEST['post']) ) {
    	$music_artist = get_post_meta((int)$_REQUEST['post'],'music_artist',true);
    }
    
	$music_buy = '';
	if ( isset($_REQUEST['post']) ) {
    	$music_buy = get_post_meta((int)$_REQUEST['post'],'music_buy',true);
    }
    
	$music_price = '';
	if ( isset($_REQUEST['post']) ) {
    	$music_price = get_post_meta((int)$_REQUEST['post'],'music_price',true);
    }
    
	$music_duration = '';
    if ( isset($_REQUEST['post']) ) {
    	$music_duration = get_post_meta((int)$_REQUEST['post'],'music_duration',true);
    }
    
	$check = "";
    if ( isset($_REQUEST['post']) ) {
    	$check = get_post_meta((int)$_REQUEST[post],'music_thumb_url_check',true);
    }
    
	$music_thumb_url = '';
    if ( isset($_REQUEST['post']) ) {
    	$music_thumb_url = get_post_meta((int)$_REQUEST['post'],'music_thumb_url',true);
    }
    
	?>

Please note that we are also closing the php tag at this point. We will reopen it later. We had to close php because we will be adding some html to the file. Above we created a function that will look through each of the input field and see if anything was saved, and if so it will auto fill those values into the fields. Lets add the inputs

<div id="track_list">

<div>
	<label for="music_mp3">MP3</label>
	<input id="music_mp3" class="widefat" name="music_mp3" value="<?php echo $music_mp3; ?>" type="text">
</div>

<div>
	<label for="music_ogg">OGG</label>
	<input id="music_ogg" class="widefat" name="music_ogg" value="<?php echo $music_ogg; ?>" type="text">
	<p style="padding-left:140px;"><a href="http://media.io/" target="_blank">Convert your music files online here</a> then use Upload/Insert <img src="images/media-button-music.gif" /></p>
</div>

<div>
	<label for="music_artist">Artist</label>
	<input id="music_artist" class="widefat" name="music_artist" value="<?php echo $music_artist; ?>" type="text">
</div>

<div>
	<label for="music_buy">URL To Purchase</label>
	<input id="music_buy" class="widefat" name="music_buy" value="<?php echo $music_buy; ?>" type="text">
</div>

<div>
	<label for="music_price">Song Price</label>
	<input id="music_price" class="widefat" name="music_price" value="<?php echo $music_price; ?>" type="text">
</div>

<div>
	<label for="music_duration">Song Duration</label>
	<input id="music_duration" class="widefat" name="music_duration" value="<?php echo $music_duration; ?>" type="text">
</div>

</div>

Try it out. Hit Add New Track and you should now see the input fields. Also you’ll notice that I added a link under OGG input, that’s just something I found online for converting mp3 files into OGG format online. We’ll style the whole thing later, for now lets make sure those input fields actually save our input, add this code.

<?php
}
add_action('save_post','catalog_save_meta');
function catalog_save_meta($postID) {
	if ( is_admin() ) {
		if ( isset($_POST['music_mp3']) ) {
			update_post_meta($postID,'music_mp3', $_POST['music_mp3']);
		}
		if ( isset($_POST['music_ogg']) ) {
			update_post_meta($postID,'music_ogg', $_POST['music_ogg']);
		}
		if ( isset($_POST['music_artist']) ) {
			update_post_meta($postID,'music_artist', $_POST['music_artist']);
		}
		if ( isset($_POST['music_buy']) ) {
			update_post_meta($postID,'music_buy', $_POST['music_buy']);
		}
		if ( isset($_POST['music_price']) ) {
			update_post_meta($postID,'music_price', $_POST['music_price']);
		}
		if ( isset($_POST['music_duration']) ) {
			update_post_meta($postID,'music_duration', $_POST['music_duration']);
		}
	}
}

Ok, now if you try saving, it will save the data. We now have fully functional custom post type. Lets add some css to it. Open playlist-style.css, remember earlier we added a custom css file into our custom post type code? Lets style those inputs. Add the following.

/* Playlist Overview Page */
.column-thumbnail { width: 125px; padding:5px !important; }
/* Custom CSS For Post Type */
#track_list { background:url(../images/playlist_bg.png) no-repeat right center;}
#track_list label { display:block; width:130px !important; float:left; padding-top:15px; padding-right:10px; text-align:right; }
#track_list div {  clear:both !important; margin-bottom:10px; }
#track_list input { height:40px !important; width:440px !important;}

/* Input Icons */
#music_mp3 { background:url(../images/note_icon.png) no-repeat right center #fff; }
#music_ogg { background:url(../images/note_icon.png) no-repeat right center #fff; }
#music_artist { background:url(../images/artist_icon.png) no-repeat right center #fff; }
#music_rating { background:url(../images/rating_icon.png) no-repeat right center #fff; }
#music_buy { background:url(../images/url_icon.png) no-repeat right center #fff; }
#music_price { background:url(../images/money_icon.png) no-repeat right center #fff; }
#music_duration { background:url(../images/clock_icon.png) no-repeat right center #fff; }

We are now completely finished with our custom post type.

One more file to edit…

Remember this code I showed earlier?

var myPlaylist = [
{
  mp3:'mix/1.mp3',
  oga:'mix/1.ogg',
  title:'Sample',
  artist:'Sample',
  rating:4,
  buy:'#',
  price:'0.99',
  duration:'0:30',
  cover:'mix/1.png'
}
];

That’s basically all the information that we will be prefilling with our custom post type we created and the meta box. Open and add the following code into playlist.php.

<script type="text/javascript">
var myPlaylist = [
<?php query_posts(array('post_type' => 'playlist')); ?>

<?php while(have_posts()): the_post(); ?>
<?php $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id ( $post->ID ), "album-thumb"); ?>

	{
		mp3:'<?php echo get_post_meta(get_the_ID(),'music_mp3',true); ?>',
		oga:'<?php echo get_post_meta(get_the_ID(),'music_ogg',true); ?>',
		title:'<?php the_title() ?>',
		artist:'<?php echo get_post_meta(get_the_ID(),'music_artist',true); ?>',
		buy:'<?php echo get_post_meta(get_the_ID(),'music_buy',true); ?>',
		price:'<?php echo get_post_meta(get_the_ID(),'music_price',true); ?>',
		duration:'<?php echo get_post_meta(get_the_ID(),'music_duration',true); ?>',
		cover:'<?php echo $thumbnail[0] ?>'
	},
  
<?php endwhile; ?>

];
</script>

This is our custom loop for custom post type “playlist”. I am using get_post_meta to pull the required data. This is all that we need for the loop. In the next section we will fire up the actual music player. Actually before we go on we need to make small addition to the functions.php file. Open it and add the following line in the // Post Thumbnails area. This is to make sure that when someone add a featured image it crops it to 125×125.

add_image_size('album-thumb', 125, 125, true); // Album Cover > Cropped

That should now look like this…

// Post Thumbnails
add_theme_support('post-thumbnails'); set_post_thumbnail_size(150, 150); // Post Thumbnails add_image_size('album-thumb', 125, 125, true); // Album Cover > Cropped

That’s it, lets move on.


Step 4 Getting it Working – The Music Player

Ok, now that our custom post type is fully really lets connect it all to the music player.

Go back to the theme directory and open header.php. All the following.

<!-- Playlist Styles -->
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/playlist/css/playlist.css">

<!-- Playlist JavaScripts -->
<script src="<?php bloginfo('template_url'); ?>/playlist/js/jplayer.js"></script>
<script src="<?php bloginfo('template_url'); ?>/playlist/js/music-player.js"></script>
<script>
	$(document).ready(function(){
		$('.music-player').ttwMusicPlayer(myPlaylist, {
			tracksToShow:3,
			description:'Hello, this is a demo description',
			jPlayer:{
				swfPath: '<?php bloginfo('template_directory'); ?>/playlist/js/',
			}
		});
	});
</script>

If you followed the tutorial correctly you should now have a fully working music player. Congratulations!


If you made this for personal use you can just easily change the appearance of the music player as you see fit. But if you are like me and choose to take it even further than lets keep going. For example if I was making this for a client I know they wouldn’t want to have anything to do with css files. I need to create a “theme options” page. For this tutorial I will call it Player Settings page and we will stick it into the Playlist menu just below the Add New Track.

I won’t be making too much options, but just enough for you guys to easily just add more if you need to.


Step 5 Player Settings – General Appearance

Copy settings folder from the downloaded source files and paste it into your blank theme folder. Inside the settings folder create a php file and name it settings.php than open up css folder and create settings-style.css. Than go back and inside the js folder create file called settings-script.js. See folder structure picture below and make sure everything matches up!


Settings.php

Yes, open up settings.php and lets write some options. First we need to do is attach those css and js files we have inside the settings folder. Use this code to do that.

<?php
  // JavaScript
  add_action('admin_init', 'settings_page_include_js');
  function settings_page_include_js(){
  wp_register_script('settings_page_js', get_template_directory_uri().'/settings/js/settings-script.js', false);
  wp_enqueue_script('settings_page_js');
  wp_register_script('settings_page_js_colorpicker', get_template_directory_uri().'/settings/js/colorpicker.js', false);
  wp_enqueue_script('settings_page_js_colorpicker');
}
// CSS
  add_action('admin_print_styles', 'settings_page_include_styles');
  function settings_page_include_styles(){>
  wp_register_style('settings_page_style', get_template_directory_uri().'/settings/css/settings-style.css', false);
  wp_enqueue_style('settings_page_style');
  wp_register_style('settings_page_colorpicker', get_template_directory_uri().'/settings/css/colorpicker.css', false);
  wp_enqueue_style('settings_page_colorpicker');
}

Here we added js and css for colorpicker as well as the custom scripts that we will write in a little bit. Next piece of code will initialize our options and add player settings page into the submenu of Playlist post type.

/* Init plugin options to white list our options */
add_action( 'admin_init', 'theme_options_init' );
function theme_options_init(){
register_setting( 'odthemes_options', 'odthemes_theme_options', 'theme_options_validate' );
}
/* Add Player Settings Menu to the custom post type 'tracklist' */
add_action( 'admin_menu', 'theme_options_add_page' );
function theme_options_add_page() {
add_submenu_page('edit.php?post_type=playlist', __( 'Player Settings', 'odthemes' ), __( 'Player Settings', 'odthemes' ), 'edit_theme_options', 'theme_options', 'theme_options_do_page' );
}

/* Create the options page */
function theme_options_do_page() {
if ( ! isset( $_REQUEST['settings-updated'] ) )
$_REQUEST['settings-updated'] = false;
  
?>

If you refresh your dashboard page you will not see the link as of yet, that’s because we haven’t actually told WP to run the settings.php file. So go back to the root of your theme folder and open functions.php and add this piece of code.

define('OD_THEME_OPTIONS', TEMPLATEPATH . '/settings/');	// Theme Options Directory

require_once( OD_THEME_OPTIONS . '/settings.php' );	// Get Settings 

With our old functions.php code, the lines should look like this…

// DEFINE PATHS
define('OD_PLAYER', TEMPLATEPATH . '/playlist/');	// Playlist Directory
define('OD_THEME_OPTIONS', TEMPLATEPATH . '/settings/');// Theme Options Directory
  
// REQUIRE FILES
require_once(OD_PLAYER . '/playlist-post-type.php');	// Get Custom Post Type : Playlist
require_once( OD_THEME_OPTIONS . '/settings.php' );	// Get Settings 

Now, go back to your settings.php file and lets keep going. At this point if you refresh your page it will give you syntax error. That’s ok, because we closed the php while our function is still open. We will be adding html code inside that function. Once we finish adding the html code and close the function the syntax error will go away.

Lets keep adding code to the end of settings.php file.

<!-- OD Panel Page Wrap -->
<form method="post" action="options.php">
<div id="od-panel">

<!-- Border Styles all around -->
<div class="glowbr">

<!-- Header -->
<div id="od_header" class="polish">
	<a id="od_logo" href="<?php echo get_admin_url(); ?>edit.php?post_type=playlist&page=theme_options">OD Themes Framework</a>
	<div class="clear"></div>
</div>

<div id="od_bar"></div> <!-- Graphic Bar below the header -->
<!-- END Header -->

<!-- Save Changes Main Button -->
<div class="button-zone-wrapper zone-top">
	<div class="button-zone">
		<span class="top"><button class="save secondary" id="od_save" name="od_save" type="submit"><?php _e("Save Changes","odfw"); ?></button></span>
	</div>
</div>

<?php settings_fields( 'odthemes_options' ); ?>
<?php $options = get_option( 'odthemes_theme_options' ); ?>

<!-- Content Container -->
<div id="od_main">
<!-- WE WILL BE ADDING PAGE CONTENT CODE HERE -->
<div class="clear"></div>
</div><!-- END Content Container -->
</div>

<?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
<div class="updated fade"><p><strong><?php _e( 'Options saved', 'odthemes' ); ?></strong></p></div>
<?php endif; ?>

</div>
</form>
<!-- END OD Panel Page Wrap -->

<?php
}
?>

I added some comments into the code so I don’t have to really explain what is what. If there are any questions please add a comment otherwise just look at the code its basic html. If you refresh now you will be able to see our new menu item named Player Settings show up. The page is blank with title and save changes button.

Lets add some pages to it.

<!-- Sidebar Navigation Container -->
<div id="od-panel-sidebar">
	<ul class="tabs">
		<li class="general"><a href="#od-panel-section-general">General Settings</a></li>
		<li class="appearance"><a href="#od-panel-section-appearance">Player Appearance</a></li>
		<li class="misc"><a href="#od-panel-section-misc">Miscellaneous</a></li>
	</ul>
</div>

Those will be our tabs. Now we will add a container for the tab page, assign each section an id so we can later target that specific page to the tab.

<!-- Tabs Containers -->
<div id="od-panel-content" class="tab_container">
<!-- General Section | Tab 1 -->
<div class="od-panel-section tab_content" id="od-panel-section-general">
		
<!-- Number of Tracks to Display -->
<div class="od-panel-field">
	<fieldset class="title">
		<label class="description" for="odthemes_theme_options[music_tracks_to_show]"><?php _e( 'Number of Tracks', 'odthemes' ); ?></label>
		<div class="od-panel-description">Number of tracks to display on the playlist?</div>
	</fieldset>
	<fieldset class="data">
		<input id="odthemes_theme_options[music_tracks_to_show]" class="regular-text" type="text" name="odthemes_theme_options[music_tracks_to_show]" value="<?php esc_attr_e( $options['music_tracks_to_show'] ); ?>" />
	</fieldset>
<div class="clear"></div>
</div>

<!-- Descripiton Text -->
<div class="od-panel-field">
	<fieldset class="title">
		<label class="description" for="odthemes_theme_options[music_player_description]"><?php _e( 'Description', 'odthemes' ); ?></label>
		<div class="od-panel-description">Add description for the player.</div>
	</fieldset>
	<fieldset class="data">
		<textarea id="odthemes_theme_options[music_player_description]" class="large-text" cols="50" rows="10" name="odthemes_theme_options[music_player_description]"><?php echo esc_textarea( $options['music_player_description'] ); ?></textarea>
	</fieldset>
<div class="clear"></div>
</div>
</div>
</div> <!-- END Tabs Containers -->

In the above code I already added some options. Basically this is the General Section Tab div that has two options. Options can be added by just adding another div with class “od-panel-field”. The options that I added are Number of Tracks to show and Description of the music player.

Lets add the other two sections. Player Appearance and Miscellaneous

<!-- Appearance Section | Tab 2 -->								
<div class="od-panel-section tab_content" id="od-panel-section-appearance">

<!-- Change Appearance Checkbox -->
<div class="od-panel-field">
	<fieldset class="title">
		<label class="description" for="odthemes_theme_options[od_custom_css]"><?php _e( 'Use Custom Styles?', 'odthemes' ); ?></label>
		<div class="od-panel-description">Are you going to change the appearance of your music player?</div>
	</fieldset>
	<fieldset class="data">
		<input id="odthemes_theme_options[od_custom_css]" class="checkme" name="odthemes_theme_options[od_custom_css]" type="checkbox" value="1" <?php checked( '1', $options['od_custom_css'] ); ?> />
	</fieldset>
<div class="clear"></div>
</div>

<!-- Show Settings if Appearance checkbox is checked -->
<div id="extra">

<!-- Description Font Color -->
<div class="od-panel-field">
	<fieldset class="title">
		<label class="description" for="odthemes_theme_options[od_font_color]"><?php _e( 'Player Description Color', 'odthemes' ); ?></label>
		<div class="od-panel-description">Change the color of the description page. <br />(ex. enter hex #CCCCCC or click to choose)</div>
	</fieldset>
	<fieldset class="data">
		<input id="colorpicker" class="regular-text" type="text" name="odthemes_theme_options[od_font_color]" value="<?php esc_attr_e( $options['od_font_color'] ); ?>" />
	</fieldset>
<div class="clear"></div>
</div>

<!-- Description Font Size -->
<div class="od-panel-field">
	<fieldset class="title">
		<label class="description" for="odthemes_theme_options[od_font_size]"><?php _e( 'Player Description Font Size', 'odthemes' ); ?></label>
		<div class="od-panel-description">Change description font size. <br />(ex. 12px or 2em)</div>
	</fieldset>
	<fieldset class="data">
		<input id="odthemes_theme_options[od_font_size]" class="regular-text" type="text" name="odthemes_theme_options[od_font_size]" value="<?php esc_attr_e( $options['od_font_size'] ); ?>" />
	</fieldset>
<div class="clear"></div>
</div>

</div> <!-- END Show Settings if Appearance checkbox is checked -->
</div>

<!-- Miscellaneous Section | Tab 3 -->
<div class="od-panel-section tab_content" id="od-panel-section-misc">

<!-- Footer Text -->
<div class="od-panel-field">
	<fieldset class="title">
		<label class="description" for="odthemes_theme_options[od_footer_text]"><?php _e( 'Player Footer Text', 'odthemes' ); ?></label>
		<div class="od-panel-description">Change footer text.</div>
	</fieldset>
	<fieldset class="data">
		<input id="odthemes_theme_options[od_footer_text]" class="regular-text" type="text" name="odthemes_theme_options[od_footer_text]" value="<?php esc_attr_e( $options['od_footer_text'] ); ?>" />
	</fieldset>
<div class="clear"></div>
</div>

</div>

Brief explanations about these two sections. In Appearance we added a checkbox if checked we will use jQuery to show options but if it’s unchecked the options will be hidden. Available options are to change description text color and font size. In the Miscellaneous section we added just one option and that will be footer area text.

Nothing is being saved yet. Lets make sure we can save our options! Paste this last piece of code to the settings.php file. Make sure it’s added to the very last line…

<?php
/* Sanitize and validate input. Accepts an array, return a sanitized array. */
function theme_options_validate( $input ) {
// Our checkbox value is either 0 or 1
if ( ! isset( $input['od_custom_css'] ) )
$input['od_custom_css'] = null;
$input['od_custom_css'] = ( $input['od_custom_css'] == 1 ? 1 : 0 );
// Text input
$input['music_tracks_to_show'] = wp_filter_nohtml_kses( $input['music_tracks_to_show'] );
$input['od_font_color'] = wp_filter_nohtml_kses( $input['od_font_color'] );
$input['od_font_size'] = wp_filter_nohtml_kses( $input['od_font_size'] );
$input['od_footer_text'] = wp_filter_nohtml_kses( $input['od_footer_text'] );
// Textarea
$input['music_player_description'] = wp_filter_post_kses( $input['music_player_description'] );
return $input;
}

Now that all our options are being saved, lets make this page look good.


Javascript

Before we add the styles, lets add the javascript functions. Go into your js folder and open settings-script.js file. Add the following code. This is a function that we will use to change the color of a div to red when someone makes a change to any options.

// Function that will change color do a div whenver someone makes a change to the input fields
function activate_save_animation(e){
jQuery('.button-zone').animate({
	backgroundColor: '#f3d9d9',
	borderLeftColor: '#555',
	borderRightColor: '#555'
});
jQuery('.button-zone button').addClass('save-me-fool');
}

The next piece of code is used to see if the checkbox in the Player Appearance section is checked or not. If it’s not checked it will hide the div with an id of “extra”.

// This bit of code shows extra options if the checkbox is checked
jQuery(document).ready(function($) {
if($('.checkme').is(':checked')){
	$("#extra").show("fast");
} else
{
	$("#extra").css("display","none");
}
});
jQuery(document).ready(function($){
$(".checkme").click(function(){
if ($(".checkme").is(":checked")) {
	$("#extra").show("fast");
} else {
	$("#extra").hide("fast");
}
});

Just below the previous code lets add this next code. We created a function to change the background color to red when someone makes a change, now we have to initialize it.

// If there was a change to the input fields fire up the 'activate_save_animation' functions
$('#od-panel input, #od-panel select,#od-panel textarea').live('change', function(e){
	activate_save_animation(e);
);

You can give it a test now, try changing any options and you’ll notice that the background around "Save Changes" changes the color. The next code will activate our tabs.

// Script for Tabs
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify theactive tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});

Test it now, they should now navigate to their specific tab content. The last code we will add is for the color picker.

// Script for color picker
$('#colorpicker').ColorPicker({
	color: '#ffffff',
	onShow: function (colpkr) {
		$(colpkr).fadeIn(500);
		return false;
	},
	onHide: function (colpkr) {
		$(colpkr).fadeOut(500);
		return false;
	},
	onChange: function (hsb, hex, rgb) {
		$('#colorpicker').attr('value', '#' + hex);
	}
});
});

That should be the whole js code we’ll need.


CSS

Lets make sure everything looks good. Go to css folder and open settings-style.css file. First bit of code will fix up the layout a bit and add some icons.

/* Layout Styling */
.glowbr { background:#FFFFFF; border:1px solid #ddd; padding:5px; margin:0 auto;  }

/* Icons */
#od-panel-sidebar li.general { background:url(../images/general_icon.png) no-repeat center right; }
#od-panel-sidebar li.general:hover { background-color: #eaeaea; }
#od-panel-sidebar li.appearance { background:url(../images/appearance_icon.png) no-repeat center right; }
#od-panel-sidebar li.appearance:hover { background-color: #eaeaea; }
#od-panel-sidebar li.misc { background:url(../images/misc_icon.png) no-repeat center right; }
#od-panel-sidebar li.misc:hover { background-color: #eaeaea }
#od_logo { background:url(../images/od_logo.png) no-repeat; display:block; width:353px; height:71px; text-indent:-9999px; float:left;  }
#od_header{ height:70px; background:url(../images/head_bg.jpg) repeat scroll; border-bottom: 1px solid #fff; padding:15px 0 15px 20px; }
#od_bar { display:block; background:url(../images/border_strip.jpg) repeat-x; height:8px; width:100%; }
#od_subheader { background:url(../images/head_bg.jpg) repeat scroll; border-bottom: 1px solid #fff; height: 35px; padding: 0 10px; }
#od_subheader { background:url(../images/head_bg.jpg) repeat scroll;	border-bottom: 1px solid #fff; height: 35px;	padding: 0 10px; }
#od_subheader .sublinks { float: left; }
#od_subheader .savelink { float: right; padding-top:5px; }
#od_subheader .savelink img {	vertical-align:middle; }
#od_subheader a { color: #8d8d8d;	font-size: 11px;	text-decoration:none;	line-height:35px; }
#od_subheader .sublinks a	{ padding: 2px 20px; }
#od_subheader .sublinks a:hover	{ color:#4ca0bf; }
.subicon_support { background:url(../images/support_icon.png) 0 0 no-repeat; }
.subicon_documentation	{ background:url(../images/documentation_icon.png) 0 0 no-repeat; }
.subicon_log { background:url(../images/log_icon.jpg) 0 0 no-repeat; }
.subicon_at { background:url(../images/at_icon.png) 0 0 no-repeat; }
#od-panel { margin-top:30px; margin-right:20px; width: 785px; }
#od_main {  box-shadow: 0 1px 0 rgba(255,255,255,0.8) inset; -webkit-box-shadow: 0 1px 0 rgba(255,255,255,0.8) inset; -moz-box-shadow: 0 1px 0 rgba(255,255,255,0.8) inset; border: 1px solid #e3e3e3; border-top: 0; background: #fff url(../images/odfw_sidebar_bg.jpg) repeat-y top left; }
#od-panel-sidebar { float:left; width:160px; overflow: visible; margin-bottom:20px;  }
#od-panel-sidebar ul, #od-panel-sidebar li { list-style-type:none; margin:0; padding:0; }
#od-panel-sidebar a { display:block; font-size:11px; padding:8px 10px; border-bottom:1px solid #ccc; text-decoration:none; color:#333333;  }
#od-panel-sidebar li.active a { box-shadow: none;	-moz-box-shadow: none; background-color:#fff;	-webkit-box-shadow: none; width: 141px; }
#od-panel-content {  padding: 20px; margin-left: 0; float: left;	width: 570px;}
#od-panel-content, #od-panel-content p { font-size:11px; color:#666; }
.od-panel-section { display:none; }
.od-panel-section.od-panel-active { display:block; }

The last css code will style the buttons and the form fields.

/*  Button Style */
#od-panel input[type="submit"], #od-panel input[type="button"], #od-panel button, #od-panel .button{ 
	font-family: Arial, Tahoma, sans-serif; 
	font-weight: bold; 
	border: 1px solid #2356a1; 
	padding: 9px 15px; 
	color: #fff; 
	-moz-border-radius: 5px; 
	-webkit-border-radius: 5px; 
	border-radius: 5px; 
	text-shadow: 0 -1px 0 hsla(214,100%,0%,.5); 
	background: #1161a0; 
	cursor: pointer;
	background: -webkit-gradient( linear, left top, left bottom, color-stop(.2, #3fa0ff), color-stop(1, #2356a1) );
	background: -moz-linear-gradient( center top, #3fa0ff 20%, #2356a1 100% );
	-webkit-box-shadow: inset 0 1px 1px hsla(0,100%,100%,.4), inset 0 -1px 0 hsla(0,100%,100%,.3), 0 4px 0 hsla(212,77%,26%,1), 0 5px 2px hsla(214,100%,0%,.5);
	-moz-box-shadow: inset 0 1px 1px hsla(0,100%,100%,.4), inset 0 -1px 0 hsla(0,100%,100%,.3), 0 4px 0 hsla(212,77%,26%,1), 0 5px 2px hsla(214,100%,0%,.5);
	box-shadow: inset 0 1px 1px hsla(0,100%,100%,.4), inset 0 -1px 0 hsla(0,100%,100%,.3), 0 4px 0 hsla(212,77%,26%,1), 0 5px 2px hsla(214,100%,0%,.5);
}
#od-panel input[type="submit"]:hover, #od-panel input[type="button"]:hover, #od-panel button:hover, #od-panel .button:hover { 
	background: -webkit-gradient( linear, left top, left bottom, color-stop(.2,#5cabf8), color-stop(1, #3970c0) ); 	
	background: -moz-linear-gradient( center top, #5cabf8 20%, #3970c0 100% ); }
#od-panel input[type="submit"].secondary, #od-panel input[type="button"].secondary, #od-panel button.secondary, #od-panel .secondary { 
	border-color: #dddddd;	
	background: #eeeeee; 
	color: #555;text-shadow: 0 1px 0 hsla(0,0%,100%,1);
	background: -webkit-gradient( linear, left top, left bottom, color-stop(0, #f7f7f7), color-stop(1, #eeeeee) );
	background: -moz-linear-gradient( center top, #f7f7f7 0%, #eeeeee 100% );
	box-shadow: inset 0 1px 1px hsla(0,100%,100%,.4), inset 0 -1px 0 hsla(0,100%,100%,.3), 0 4px 0 hsla(0, 0%, 86%,1), 0 5px 2px hsla(0,0%,0%,0.5);
	-moz-box-shadow: inset 0 1px 1px hsla(0,100%,100%,.4), inset 0 -1px 0 hsla(0,100%,100%,.3), 0 4px 0 hsla(0, 0%, 86%,1), 0 5px 2px hsla(0,0%,0%,0.5);
	-webkit-box-shadow: inset 0 1px 1px hsla(0,100%,100%,.4), inset 0 -1px 0 hsla(0,100%,100%,.3), 0 4px 0 hsla(0, 0%, 86%,1), 0 5px 2px hsla(0,0%,0%,0.5); }
#od-panel input[type="submit"].secondary:hover, #od-panel input[type="button"].secondary:hover, #od-panel button.secondary:hover, #od-panel .secondary:hover { background: -webkit-gradient( linear, left top, left bottom, color-stop(.2, #f2f2f2), color-stop(1, #eee) ); background: -moz-linear-gradient( center top, #f2f2f2 20%, #eee 100% ); }
#od-panel input[type="submit"]:active, #od-panel input[type="button"]:active, #od-panel button:active, #od-panel .button:active { box-shadow: none;	-moz-box-shadow: none; -webkit-box-shadow: none; margin-top: 5px; margin-bottom: -5px; }
#od-panel input[type="submit"].secondary:active, #od-panel input[type="button"].secondary:active, #od-panel button.secondary:active, #od-panel .secondary:active { box-shadow: none; -moz-box-shadow: none; -webkit-box-shadow: none;	margin-top: 5px; margin-bottom: -5px; }
#od-panel .button-zone-wrapper {	clear: both; height: auto; background: #f1f1f1; box-shadow: 0 1px 0 rgba(255,255,255,0.8) inset; -webkit-box-shadow: 0 1px 0 rgba(255,255,255,0.8) inset; -moz-box-shadow: 0 1px 0 rgba(255,255,255,0.8) inset; border: 1px solid #e3e3e3;	z-index:999; }
#od-panel .button-zone {	padding: 10px; height:40px; z-index: 150; line-height: 1em; text-align: center; }
#od-panel fieldset { width: 50%; max-width: 50%; float: left; position: relative; }

/* Form Styles */
#od-panel-content fieldset.title{	width: 45%; margin-right: 5%; }

/* Fields Styling */
#od-panel-content .od-panel-field { margin-bottom:15px; padding-bottom:15px; border-bottom:1px dashed #eee; }
#od-panel-content label { font-weight:bold; color:#444; font-size:12px; margin-bottom:5px; text-shadow:1px 0 0 #fff; }
#od-panel-content .od-panel-description { font-style:italic; margin-bottom:5px; color:#777; text-shadow:1px 0 0 #fff; }
#od-panel-content input[type=text], #od-panel-content textarea, #od-panel-content option, #od-panel-select { border:1px solid #ddd; color:#666; font-size:11px; background:#fff; border-radius:0; -moz-border-radius:0; -webkit-border-radius:0;  }
#od-panel-content input[type=text], #od-panel-content textarea { padding:5px; }
#od-panel-content input[type=text] { width:270px; }
#od-panel-content textarea {  height:100px; }

That is all for css styles. We are now completely done with the settings page.


Hooking Up Our Options

Ok, lets hook all our options to our music player. Go back to the theme root folder and open header.php file. On the very top of the file add this piece of code, it will get all of our options.

<?php  $options = get_option('odthemes_theme_options'); ?>

Add this code bellow the <!– Playlist Styles –> section, where your css is. This code is our custom css style which we set up in the Player Appearance settings page.

<?php if( $options['od_custom_css'] == '1' ) : ?>
<style type="text/css" media="screen">
.description { 
<?php if( $options['od_font_color'] != '' ) : ?>color:<?php echo $options['od_font_color']; ?> !important; <?php else: ?><?php endif; ?>
<?php if( $options['od_font_size'] != '' ) : ?>font-size:<?php echo $options['od_font_size']; ?> !important; <?php else: ?><?php endif; ?>
}
</style>
<?php else: ?>
<?php endif; ?>

You can now add some custom color and text size to the description text. Try it out and if all went well, they changes should take effect.

Lets make some more changes, find this js code just below…

<script>
$(document).ready(function(){
$('.music-player').ttwMusicPlayer(myPlaylist, {
	tracksToShow:2,
	description:'Hello, this is a demo description',
	jPlayer:{
		swfPath: '<?php bloginfo('template_directory'); ?>/playlist/js/',
	}
	});
});
</script>

We have the option to change the number of tracks and the description text. Lets add some code so it can actually work. Change this:

	tracksToShow:2,
	description:'Hello, this is a demo description',

To this…

	tracksToShow:<?php echo $options['music_tracks_to_show']; ?>,			
	description:'<?php echo $options['music_player_description']; ?>',

Now, we can tell the player how many tracks to show from the settings page. The description text can also be set.

We have one more file to edit and we’ll be done! Open footer.php file. Replace all the code you see with this one…

<?php  $options = get_option('odthemes_theme_options'); ?>
<div class="bar"></div>

<div id="footer">
	<?php if( $options['od_footer_text'] != '' ) : ?>
	<p><?php echo $options['od_footer_text']; ?></p>
<?php else: ?>
	<p><a href="http://owl-design.com/" title="Owl Design">Owl Design</a></p>
	<?php endif; ?>
</div>

</div>
</body>
</html>

This is for the Miscellaneous section where you able to add your own footer text.


We are done!

That is all, we are now finished with the music player and a custom settings page!


Feel free to comment on improvements that can be done or if you have suggestions, like I said I’m not a pro and this is how I got it to work.

Vadim Goncharov is owldesign on Graphicriver
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Pingback: My Stream » HTML5 WordPress Music Player & Settings Page Integration

  • http://twitter.com/drale2k Drazen Mokic

    I like the idea of the tutorial but instead of making such an ugly low contrast screenshot of a file structure which is kinda hardly readable, you should have provided some screenshots of the result in the WP Admin Backend.

    No hating, just a comment

    • Vadim
      Author

      Sorry man, you are right. This is my first tutorial ever, I will consider your comment for sure in my other tutorials. Thanks!

      • http://twitter.com/drale2k Drazen Mokic

        Everything is cool ;)

    • Connor Crosby

      I agree! I was hoping for some screenshots.

    • Jhudiel

      Sir…
      Im having a hard time making it work in IE 8 and Safari 5.. do you have any ideas about this.. this problem is really frustrating.. sorry to bother you..

  • http://www.idesignit.co.il Elron

    Looks nice, a live demo please!

  • http://lazaac.com lazaac

    I’m just lost.. they are lot of bug even the src (imgs) link stated above are different as in the zip file.. it’s so difficult for newbie like me to understand certain thing.. :( btw, thanks for this tut..

    • Vadim
      Author

      lazaac can you let me know were the bugs are happening, which images. It might be a super easy fix, let me know where you are experiencing the bugs and I will be happy to help, thanks.

  • http://wayruro.com Renzo

    Yes, a live demo would be great.

    Is there a way to use this player for background music? let’s say during a slideshow?

    Thank you for your article, keep them coming!

    • Vadim
      Author

      Well I think this might be a little too much to use as a background player. Look around google I’m sure you can find something much more light weight. But if you wanted to go this route, everything is possible.

      Demo and screenshots are coming.

  • Frei

    I’m curious about how could you make that folder structure images? Is there any software or just Photoshop?

  • Vadim
    Author

    Also forgot one mention one important piece of code. The index.php has the include function that makes the player show up. If you look at the index.php you’ll find this..

    <div class="music-player">
    <?php include (TEMPLATEPATH . ‘/playlist/playlist.php’ ); ?>
    </div>

    Basically cut and paste that into which ever template/page you wanted the music player to show up..

  • Rene

    a demo link is given at step 2 ;)

  • http://bryoz.co.uk bryoz

    Hey – thanks for this really in-depth tut!

    Only crit is that as it’s such a lengthy process, I wouldn’t really feel comfortable dedicating time to this without any examples of an end result.

    Can we please have a live demo? :)

  • http://www.ansesamaro.com Anses

    What if I want to put this player on a sidebar maybe as a widget, would it be possible?

    • Vadim
      Author

      Yes you can. You can try this plugin http://wordpress.org/extend/plugins/php-code-widget/

      It will let you insert php code inside sidebar widgets. Once you active it you can insert this code into it and it should appear in your sidebar. You may need to play around with the css to make sure everything fits good in your sidebar..

      Put this code into the php widget to get the player to show up.

      <div class=”music-player”>
      <?php include (TEMPLATEPATH . ‘/playlist/playlist.php’ ); ?>
      </div>

      Also make sure to delete that same code from your index.php. Otherwise it will either load two player or break them all together.

      Good luck.

      • http://www.ansesamaro.com/ Anses

        Thank You!

  • http://wp.envato.com/ Japh

    Congrats on your first tutorial, Vadim!

    Your folder structure images were my favourite part, I think! While it might have been better to stick with a more familiar directory structure layout, I really liked the idea behind what you were trying to do. A nice graphical representation, also showing changes.

    Looking forward to your next tutorial :)

  • Nadeem Rasheed
  • farfanoide

    hi there! i keep getting:
    Uncaught ReferenceError: myPlaylist is not defined
    don’t know exactly what’s happening…

    thanks for this tutorial and your help!

    • Vadim
      Author

      farfanoide that could happen if you place your scripts in different order. Some scripts might need to go first. For example the jplayer.js must be first then the music-player.js and the rest.

      Also make sure that your jquery is the first one. if you are using wp_enqueue_script(“jquery”); make sure its above all your javascripts.

      Another thing to check, if you were writing code by hand check if your src have the forward slash like this “/playlist/js/..”, you need the / before playlist.

      Also try changing the order of your scripts around. Hopefully you can get it fixed.

      Make sure WP find the jquery and is able to run it..

      If not email me your header.php file and I’ll look at it. vadim@owl-design.net

      Good luck man.

      • http://owl-design.com Vadim
        Author

        farfanoide was able to fix this error by changing the php version on his local server.. if anyone else experiencing this problem!

  • http://www.imageworksllc.com Joshua Briley

    Holy Moly! This is a seriously in-depth tutorial. Thanks for sharing this.

  • Pingback: A Free wordpress newsletter » WordPress News, Tutorials & Resources Roundup No.9

  • http://www.adamscottcreative.com Adam

    Hmmm…this might work for a “podcast” section of a site I am working on. Anyone set it up to do this yet?

  • Nadeem Rasheed

    I cant get the post thumbnail to show up or the music player :(

    • Vadim
      Author

      Hey, please make sure all of these items are correct and are in your code?

      functions.php

      // Post Thumbnails
      add_theme_support(‘post-thumbnails’);
      set_post_thumbnail_size(150, 150); // Post Thumbnails
      add_image_size(‘album-thumb’, 125, 125, true); // Album Cover > Cropped

      playlist.php

      <?php $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id ( $post->ID ), “album-thumb”); ?>

      and

      cover:’<?php echo $thumbnail[0] ?>’

      Please make sure all those are correct, that should get your album thumbs from your featured image post.

      Make sure there aren’t any spelling errors if you are fallowing the tutorial. Also make sure that your jquery is initialized before the player scripts.

      If you music player doesn’t show up make sure under your Player Settings > General Settings > Number of tracks has a number. If it is left blank the player doesn’t show up.

      Let me know if any of those helped. If not can you tell me more where you stopped and encountered the problem?

      • Nadeem Rasheed

        I got stuck after Step 3 ill try again on another site, and ill shoot you an email

  • http://www.idesignit.co.il/ Elron

    Cool, is there a demo for the admin panel as well?

    • Vadim
      Author

      Elron you can check out this screencast it’ll show you the admin panel demo. I’m not sure how to set it up so its secure from people breaking it so for now I can only give a video, sorry.

      http://screenr.com/vcYs

  • http://www.martineetbernard.com bernard

    Hi, here’s mine ;-)
    http://www.martineetbernard.com

    thanks a lot !

    • Vadim
      Author

      No problem I’m glad people can put it to use! :) Well worth the writing.

      Also you have to make sure you have .ogg file in there as well, I don’t think browsers such as chrome and firefox do mp3′s so if you don’t have a link to .ogg file the music won’t play. Find something to convert the mp3 files to another copy of .ogg and link it up, the link to convert mp3 to .ogg I included in the tutorial worked great for me, but I’m sure there are other converters out there.

      You need both mp3 and .ogg to make sure the music plays on major browsers. Right now it doesn’t work on firefox and chrome for me, works in IE.

      Looks great man!
      Vadim

  • http://www.martineetbernard.com bernard

    Thank you Vadim !!

  • Terry

    Can you do a tutorial not in wordpress. I am new and I having a difficult time adding this player to my we site. I do not know how to add my files . Can someone walk me through. In desperate need of help

  • Vadim
    Author

    http://www.codebasehero.com/2011/06/html-music-player/

    That tutorial is for non WordPress sites, download it and just copy and past the source code into your website.

  • Mike

    Can you add a Scrollbar to the Playlist ? How?

    • Vadim
      Author

      Not sure how that can be done, we would need someone with JavaScript skillage to figure that one out. Sorry man can’t help you there.

  • Thanos M.

    Hello Vadim!

    I got stuck at the Settings section, the Javascript part in particular. It seems that the scripts don’t load at all so whatever i write at the settings-script.js has no effect.
    The player works because its scripts are called directly from the header. I mean I think the problem is the way they are called.
    Do you have any clue how to make them run?

    Thanks a lot!

    • Vadim
      Author

      Hey, the player scripts are being loaded into the header in a different way. For the settings scripts we are loading them when a user is going inside the admin area. We do that with admin_init. Please make sure there are no spelling errors and the path to the file is correct.

      /settings/js/settings-script.js

      Make sure all that is how you have it and the js file is placed in the correct directory. Also do you have firebug? Check your console if there are any errors when you are inside your admin area, maybe it loads but there is some error within the settings-script.js file, also double check if you are no missing anything there.

      Let me know if you figure it out..
      Vadim

      • Thanos M.

        Hey Vadim,
        You were right. It was mostly spelling errors at the js script.
        Thanks a lot :)

  • Web Noob

    All these changes I would make on the back-end of WP or in the FTP File Manager? Extremely new to wordpress and web functions

    • Vadim
      Author

      Hey, you would need to make these changes to the back-end files of WP and then upload via FTP. But its super easy, I walk you through the steps, if you are stuck let me know and I can help.

  • MLA

    I figured out how it works with template, but is there anyway to add this as a plugin rather than a theme/template? How do I add the music function to a different theme? Which codes do I need to change?

    • Vadim
      Author

      There is probably a bunch of steps you need to do to make it into a plugin. That’s something that I wanted to do in the first place, but since I never made plugins before I wasn’t sure how to go about it. I will however make it into one soon, after I figure it out ;)

  • http://www.martineetbernard.com bernard

    Hi every one ! I’ve got a problem. it doesn’t work with Chrome and i don’t understand why..It did work, but today, nothing..
    Is some one have an idea to help me ?

    Thank’s a lot

    • Vadim
      Author

      Hey, it works for me on Chrome.

      Anyone else have that problem?

      • http://www.martineetbernard.com bernard

        Hi Vadim, it’s working.. i cant’ explain what happened. Sorry..Merry Christmas

  • Julian

    Hi. On step 3 you tell us to paste
    // DEFINE PATHS
    define(‘OD_PLAYER’, TEMPLATEPATH . ‘/playlist/’); // Playlist Directory

    // REQUIRE FILES
    require_once(OD_PLAYER . ‘/playlist-post-type.php’); // Get Custom Post Type : Playlist

    into wp_content/themes/xxx/functions.php

    but where must I do paste it? there’s a lot of code in that .php file. I tried to paste it in the beginning, end, middle etc, then everytime I refresh the admin wp panel I got a blank page in the browser, instead of an updated control panel with playlist tab

    thanks

    • http://www.trapartists.com Preston

      Thats exactly what happened to me Julian. Except the white page gave me an error code. I hate it when tutorials dont work out like they are suppose to :-( I hope this isnt my fault

    • Vadim
      Author

      Not sure why that is happening to you, but as we all know many times it won’t work correctly for everyone. It could possibly be because of the theme you are using. I made this using completly blank theme, so it was error free for me. Some people got it going in their custom theme fine, so I’m not sure. Make sure every path is correctly points to the folders and there is not spelling errors.

      If you are just stuck and frustrated email me your dashboard login and I can check it out maybe I can do something about it.

  • http://www.trapartists.com Preston

    Hello Vadim, this looks like an awesome tutorial and could use this player on my site. Unfortunately im having problems (as always) and was wondering if you could help. Im pretty sure i followed directions exactly. I get stuck at the beginning. You said:
    “So for that we need to go back to the main theme directory and open up functions.php file”
    Are you talking about the directory folder that says “themes” and contains all of the themes, or are you talking about the MAIN theme, the one that is activated that im using? Because my THEMES folder contains only one file which is index.php. There is no functions.php file. But if you go to the theme folder that im using and have activated, which is yoo_corona(Corona theme from YooTheme), there IS a functions.php file. This is what the functions.php file looks like…
    <?php
    /**
    * @package Corona
    * @author YOOtheme http://www.yootheme.com
    * @copyright Copyright (C) YOOtheme GmbH
    * @license YOOtheme Proprietary Use License (http://www.yootheme.com/license)
    */

    // load config
    require_once(dirname(__FILE__).'/config.php');

    This is what i did, and i ended up getting an error message…
    <?php
    /**
    * @package Corona
    * @author YOOtheme http://www.yootheme.com
    * @copyright Copyright (C) YOOtheme GmbH
    * @license YOOtheme Proprietary Use License (http://www.yootheme.com/license)
    */

    // load config
    require_once(dirname(__FILE__).'/config.php');

    // DEFINE PATHS
    define('OD_PLAYER', TEMPLATEPATH . '/playlist/'); // Playlist Directory

    // REQUIRE FILES
    require_once(OD_PLAYER . '/playlist-post-type.php'); // Get Custom Post Type : Playlist

    Let me know if you need any other info. I have no idea what could be wrong.

    • Vadim
      Author

      Yes that is the functions file you need that stuff in. Everything looks correct to me, you are doing everything correctly, so keep going down through the tutorial. Let me know if you get stuck again, I’d love to help, we’ll get it working for you ;)

      Vadim

  • Pingback: WordPress: The Best of 2011 and Future Predictions | Wptuts+

  • Pingback: Wordpress News - The Best WordPress Tips and Tutorials of 2011Wordpress News

  • http://www.trapartists.com Preston

    Hey Vadim, i am stuck at:

    var myPlaylist = [
    {
    mp3:'mix/1.mp3',
    oga:'mix/1.ogg',
    title:'Sample',
    artist:'Sample',
    rating:4,
    buy:'#',
    price:'0.99',
    duration:'0:30',
    cover:'mix/1.png'
    }
    ];

    This is what my playlist-post-type.php files looks like:

    _x(‘Playlist’,'Music Player’,'Music Player’),
    ‘singular_name’ => _x(‘Music Player’,'Music Player’, ‘Music Player’),
    ‘add_new’ => _x(‘Add New Track’, ‘Music Listing’,'Music’),
    ‘add_new_item’ => __(‘Add New Track’,'Music’),
    ‘edit_item’ => __(‘Edit Track’,'Music’),
    ‘new_item’ => __(‘New Music Post Item’,'Music’),
    ‘view_item’ => __(‘View Music Item’,'Music’),
    ‘search_items’ => __(‘Search Music Items’,'Music’),
    ‘not_found’ => __(‘Nothing found’,'Music’),
    ‘not_found_in_trash’ => __(‘Nothing found in Trash’,'Music’),
    ‘parent_item_colon’ => ”
    );

    $args = array(
    ‘labels’ => $labels,
    ‘public’ => true,
    ‘exclude_from_search’ => false,
    ‘show_ui’ => true,
    ‘capability_type’ => ‘post’,
    ‘hierarchical’ => false,
    ‘rewrite’ => array( ‘with_front’ => false ),
    ‘query_var’ => false,
    ‘menu_icon’ => get_stylesheet_directory_uri() . ‘/playlist/images/playlist.png’,
    ‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’),
    );
    register_post_type( ‘playlist’ , $args );
    }

    //Custom Overview Pageadd_action(“manage_posts_custom_column”, “music_custom_columns”);
    add_filter(“manage_edit-playlist_columns”, “my_areas_columns”);function my_areas_columns($columns)
    {
    $columns = array(
    “thumbnail” => “Album Cover”,
    “cb” => “”,
    “title” => “Track Title”,
    “artist” => “Artist Name”
    );
    return $columns;
    }
    function music_custom_columns($column)
    {
    global $post;
    if (“ID” == $column) echo $post->ID;
    elseif (“artist” == $column)
    echo get_post_meta(get_the_ID(),’music_artist’,true);
    elseif (“thumbnail” == $column) the_post_thumbnail(‘album-thumb’);
    }

    // Adding Custom Screen Icons on Edit and Add New Screens
    add_action(‘admin_head’, ‘plugin_header’);
    function plugin_header() {
    global $post_type;
    ?>

    #icon-edit { background:transparent url(”) no-repeat; }

    <link rel='stylesheet' type='text/css' href='’ />

    What do I do next? I know i have to start creating inputs, but whenever i add any more code to the playlist-post-type.php file, its breaks and i get a syntax error (using Dreamweaver CS5)

  • http://www.trapartists.com Preston

    Vadim, is there an easier way we can talk back and fourth or exchange code besides through numerous comments on here?

    • Vadim
      Author

      Yes, please email me at vadim@owl-design.net

      Let me look at your code in the next day or some, little busy at the moment. Most of the time it can be a spelling error.

      I need to understand more about the codes you added. I think your comment didn’t post the whole playlist-post-type.php file contents. Unless how you have in your comment is exactly how it is in your file, then you there will defiantly be errors ;)

      Please email me and I’ll help you as much as I can!

      Vadim

  • Pingback: WordPress Year in Review: The Best Tutorials of 2011 | Simpler Design's

  • tauras911

    Hi Vadim and all,

    First thank you for all you work and this tutorial.

    I am a super noob wordpress user, but I would really like to integrate this player into my wordpress theme. I would like to use it for

    a) A playing in a page, for 30 second samples and buy button links to amazon
    b) In a side bar for full music tracks

    After reading through the tutorial, attempting to do it and reading all the comments, I am still a bit lost =).

    So I have a few questions:
    1) in the download, there is a finished folder. Can I use that folder instead of going through the tutorial?
    2) If I used the finished folder template, then this does not effect my current theme MystiqueR3
    3) I read in the comments I might be able to use this in a sidebar using the php code widget (which I have), and even saw the example form http://www.martineetbernard.com/livre-dor/, which looks great. But, again I am uncertain of how to make the changes needed in my current theme. Should I just follow your tutorial for my theme>
    Any guidance to de-noob me on this would be fantastic!

    Oh, and btw @ http://www.annalisemorelli.com, nice website and integration. =D
    Thanks all,

    Tauras

    • Vadim
      Author

      You can use the finished folder, but you would still need to edit your theme’s files. The header.php and functions.php need to be edited. Do a search on this page for header.php and functions.php and see what type of code you need to insert into your theme files. Step 4 I think is where i start from. Ones all the files edit you need to use that php widget and insert this code into it..

      Then change the css styles to make sure it looks good on the sidebar within your theme..

      Hopefully that clears up some things.

    • Vadim
      Author
    • Vadim
      Author

      Sorry, so late here.

      <div class=”music-player”>
      <?php include (TEMPLATEPATH . ‘/playlist/playlist.php’ ); ?>
      </div>

  • Tauras911

    Also, some thoughts on the tutorial.

    it’s a long one. You lose me a bit with your wording and also I feel uncertainty when you do not explicitly tell me where to put something. For example, You will mention multiple changes that I assume need to go into the same page, but I am not certain if I need to place it above or below the last.

    So I would recommend breaking it down a bit more with explicit direction as to where to put things.

    Also, since it is a long one, making a video to accompany it, with you going through the steps visually can answer a lot of questions and fill some gaps. Together with the written tutorial it should clear some things up.

    You are miles ahead of most wordpress users in understanding this stuff, so I look forward to hopefully learning a few things here.

    Thank you again,

    Tauras

  • Mauricio

    Excellent integration.
    I have a question.
    Is it possible to create multiple playlist or create categories?

  • http://www.robbennet.com Rob

    Great Tutorial! What would be your suggestion for adding multiple playlists to a site?

    • Vadim
      Author

      Hey, unfortunately I haven’t tried it..

      Look here at the original tutorial and somewhere in the comments someone brought it up, I’m not sure if they were able to achieve it or not though..

  • http://www.trapartists.com Preston

    yeah i never figured out how to integrate within my theme…

  • http://www.trapartists.com Preston

    If anybody knows how to integrate this within a theme, please help me!

  • http://www.trapartists.com Preston

    Im getting this error and have no clue to what its trying to tell me:

    Warning: include() [function.include]: Failed opening ‘C:\xampp\htdocs\trapartists/wp-content/themes/yoo_coronaphp’’ for inclusion (include_path=’.;C:\xampp\php\PEAR’) in C:\xampp\htdocs\trapartists\wp-content\plugins\wp-php-widget\wp-php-widget.php(52) : eval()’d code on line 2

    my theme is themes/yoo_corona/ if that helps…

    • Vadim
      Author

      Preston sorry to hear you didn’t get it to work. It seems like the error is related to your yoo theme and not this script.
      Try renaming your “yoo_coronaphp” to “yoo_corona.php”, maybe the problem is that your current file don’t seem to have an extension “.php”.

      I made this tutorial on a clean theme so I don’t know how it may react to everyone’s different themes, and the plugins they have installed.

      Let me know if that changes anything.

  • falleh

    Hey! Why you just cant upload the complete modifized audio player?
    This tutorial is making me sick! :(

    • Vadim
      Author

      Falleh, if you are referring to a fully working code, then I have done that. Once you download source files there will be a folder in there with the final code. Copy the contents of that folder into your themes folder and add some code into your header.php and functions.php files.

      The purpose of this tutorial wasn’t so you can just activate it as a plugin, even though if I knew how to make plugins I would put up a link to that as well. I’m just trying to show everyone how I managed to do it for myself.

      This tutorial does have a lot of code you have to go through, but if you are completely frustrated shoot me an email and I can help you setting up the two files you need to edit to get it going..

      vadim@owl-design.net

      Thanks
      Vadim

  • Pingback: Bangladesh Web Lab | Bangladeshi Web Designer and Developer Blogs – Best WordPress Tips and Tutorials of 2011

  • Pingback: WordPress Arena: A Blog for WordPress Developers, Designers and Blogger

  • http://www.martineetbernard.com bernard

    Hi Vadim,
    I can’t explain why my 5th song doesn’t appear. It was working until today… In the “header.php” file , i put
    tracksToShow:5,
    Have you got any idea, please ?

    http://www.martineetbernard.com

    Thank you

    • Vadim
      Author

      Hey, if you change tracksToShow: to something less than 4..try 2 or whatever. Does it only show that amount? If it doesn’t work possibly something is up with javascript file, have you edited it at all?

      Also did you install any plugins recently, maybe js from those plugins cause it to break.
      I’m not sure what could be happing to it…make sure you have more than 4 tracks added in your back end too ;)

      Let me know if you have any luck..

      • http://www.martineetbernard.com bernard

        Hey vadim,
        ” maybe js from those plugins cause it to break.” yes it is.. i’ll try to resolve that.
        Thank you

  • http://html5socket.com/ html5 video player

    It would be really cool if we could at least get an option to enable the HTML5 mode jwplayer in the next Subsonic release. Not only would it bypass the need for flash, but it also has some extra features (wav playback, etc).

    It seems the biggest issue would be with flv video, but by transcoding to mp4 instead of flv, that could be solved. Even without the video fix, making it optional would allow those of us the mainly use Subsonic for music to benefit from the new player.It ends up looking almost official, and iPhone users can lokk over html5 audio player.

  • Kim

    Hey,

    Great tutorial …no problems getting it working ..But I’d really like to add more than one playlist to a page. I know this has been asked before but I was wondering if anyone figured out how? Or at least point me in the right direction when it comes to achieving this? Would be great.

  • brainfreeze

    Some questions. 1- The ‘FINISHED’ folder itself is a completed work, is it not?
    2 – Does it not display as a playlist, with a scroll bar?
    3- I added more than one to the playlist but it displayed only one even when I clicked on the next button?

    It looks fantastic. I am trying to figure out but as a newbie, some of the language here is a wee daunting to me. If you could find time, I did be much obliged. (email me) ?

    Thank you for the good work!

  • Joe

    Hey Vadim,

    I seem to be having a similar problem to bernard I have 6 tracks and only 4 show up on the playlist. I put 6 in the header section for tracksToShow: I also tried deactivating all my plugins but it didn’t resolve the issue. I haven’t modified the javascript file but if you could direct me to where in the file the problem might be occuring that would be awesome. Otherwise everything else works perfectly.

    Thanks

  • Stef

    Hi Vadim, thanks for the tut man. Some areas it was lost in translation. You’d be working on the function file but didn’t say how or where to stack the code precisely. That was a bit confusing. Only when you look at your finished file does it make sense.

    I got all the files in there, but nothing is appearing on the page….at all.

    Is there a way to call to the player for a page template? I’m lost right now and was hoping to get this thing up and running today.

    Thanks.

    Stef

  • Pingback: HTML5 WordPress Music Player & Settings Page Integration | Calin's Design

  • http://flippedscripts.com ARCH3D

    Hey. Was trying to get this to show up, got to 3.2 before I started having problems. Keep getting parse error.

  • Pingback: Integrate an HTML5 music player in your WordPress site | OCHOLABS

  • http://www.comolasgrecas.com isaiso

    Hi Vadim!
    I went through all the steps you show in this tutorial but i have found a problem. Everything seems to work properly but when i go to see the preview of a playlist I get a 404 error. I also have checked on your screencast video and I don’t find the “HTML5 music player” tittle link at the top of the dashboard editor pages. Actually the /wordpress/playlist/playlist1/ path doesn’t exist.

    Could you have an idea about where i made a mistake?

    This is a great tutorial thanks for sharing.

  • Vadim

    Sorry guys, I’ve been super busy and wasn’t able to check all the comments and problems people are having. I will try to answer and help everyone next week when I have a little more time on my hands…

    sorry again!

  • patrick

    any development on this? i’d LOVE to get this working for a buddy’s site I’m working on… Vadim – thanks for all the work on it…

  • Pingback: Player audio e video gratuiti — Studio404 Web Agency

  • Rose

    I like this player. Is there a way I can use this player outside of WordPress? I have tried to use the Codebasehero files
    but can’t get it to work….Also, is there a way to have a download function on the MP3s?

  • http://pinnaclenetworking.com PNetDesigns

    Awesome tutorial, however… when I start making the settings.php is sends the site I am implementing this on into a 500 error…. I’ve poked the code and copied it exact, but still cannot find the offending code…. please advise?

  • http://twitter.com/twittem Edward McIntyre

    Thanks for the awesome tutorial.

    My player works but has a weird issue. I will randomly stop playing 3/4 of the way through a song… Has anyone else run into this?

    My player is located at: http://player.shakethelake.ca/frame/

  • http://www.enigmaweb.com.au EnigmaWeb

    Hello All, just letting you know this player is now available as an official plugin on the WordPress repository – http://wordpress.org/extend/plugins/html5-jquery-audio-player/

  • http://www.allghanamusic.com/ James

    That is a nice Job u did there mate.

    I was just wondering if this could also be implemented in standalone mode or even better yet integrated in other scenarios other than WP say a regular site powered by good old PHP and HTML and some DB.

    Thanks.

  • http://www.maxqdesigns.com/ Simon Berube

    I’ve been trying to make this function within Android phones. Has anyone had luck? I tried to start conversation about the Android issues, posted to Codebasehero, but it is awaiting moderation. With the Android SDK installed, and emulating a 2.3.3 phone, watching the Debug Monitor, I can see lots of the following errors:

    mediaplayer went away with unhandled events
    Attempt to call getDuration without a valid mediaplayer

  • Mark

    I’m surprised no one mentioned that this doesn’t work in IE7, IE8, and IE9

  • ciro cid

    Hi Vadim

    First of all thanks a lot, this works great

    I´m trying to add lyrics to my player using the editor as the source.

    I added a fourth variable to the $title, $artist, $albumCover group called $lyric inside music-player.js.

    I added styling for it on playlist.css

    and added

    lyric:”

    to playlist.php, and it works, but only without formatting, do you know why???

    I´m a total newbie.

    Ciro

  • yiran

    great works! thx!