Created
April 2, 2019 10:44
-
-
Save wolfthemes/d1c5de90616899639686f75b1dc0815b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$streaming_player_id = 10269; // your playlist ID | |
$streaming_player_url = 'http://dreamsiteradiocp3.com:8010/stream'; // your streaming URL | |
/** | |
* Overwrite sticky player tracklist to play audio streaming | |
*/ | |
function radio_stream( $tracklist, $post_id ) { | |
global $streaming_player_id, $streaming_player_url; | |
if ( 'mp3' !== pathinfo( $streaming_player_url, PATHINFO_EXTENSION ) ) { | |
$streaming_player_url = $streaming_player_url . '.mp3'; | |
} | |
if ( $streaming_player_id === $post_id ) { | |
$tracklist[0]['audioUrl'] = $streaming_player_url; | |
$tracklist[0]['mp3'] = $streaming_player_url; | |
} | |
return $tracklist; | |
} | |
add_filter( 'wpm_playlist_tracks', 'radio_stream', 10, 2 ); | |
/** | |
* Additional post CSS | |
* | |
* @see wp_add_inline_style() | |
*/ | |
function radio_custom_streaming_player_css() { | |
$css = ''; | |
global $streaming_player_id; | |
ob_start(); | |
?> | |
/* Hide prev/next buttons, toggle playlist and time bar */ | |
#wpm-playlist-<?php echo $streaming_player_id; ?> .mejs-previous-button, | |
#wpm-playlist-<?php echo $streaming_player_id; ?> .mejs-next-button, | |
#wpm-playlist-<?php echo $streaming_player_id; ?> .mejs-toggle-playlist-button, | |
#wpm-playlist-<?php echo $streaming_player_id; ?> .mejs-time-rail, | |
#wpm-playlist-<?php echo $streaming_player_id; ?> .mejs-time, | |
#wpm-playlist-<?php echo $streaming_player_id; ?> .wpm-tracks{ | |
display: none!important; | |
} | |
/* Adjust title position */ | |
#wpm-playlist-<?php echo $streaming_player_id; ?> .mejs-layers{ | |
top: 50%; | |
position: relative; | |
transform: translateY(-50%); | |
margin-top: -5px; | |
} | |
<?php | |
$css = ob_get_clean(); | |
wp_add_inline_style( 'snakepit-style', $css ); | |
wp_add_inline_style( 'wolftheme-style', $css ); | |
} | |
add_action( 'wp_enqueue_scripts', 'radio_custom_streaming_player_css', 20 ); | |
/** | |
* Overwrite player features to disable "cuehistory" | |
* | |
* By default, the player will try to continue to play where it stops. | |
* It causes a glitch when a live stream is played | |
* Prevent lag when reloading the page | |
*/ | |
function radio_stream_cue_features( $features ) { | |
$features = array( | |
'cuebackground', | |
//'cuehistory', | |
'cueartwork', | |
'cuecurrentdetails', | |
'cueprevioustrack', | |
'playpause', | |
'cuenexttrack', | |
'progress', | |
'current', | |
'duration', | |
'cueplaylist', | |
'cueplaylisttoggle', | |
); | |
return $features; | |
} | |
add_filter( 'wpm_cue_features', 'radio_stream_cue_features' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment