| 1 |
/** |
| 2 |
* jsMediaPlayer 1.7.0 for Blubrry PowerPress |
| 3 |
* |
| 4 |
* http://www.blubrry.com/powepress/ |
| 5 |
* |
| 6 |
* Copyright (c) 2008-2018 Angelo Mandato (angelo [at] mandato {period} com) |
| 7 |
* |
| 8 |
* Released under Aoache 2 license: |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* version 1.1.0 - 09/29/2018 - Added skip to position in player code |
| 12 |
* version 1.6.0 - 06/14/2017 - Added code to deal with IE/Edge preloading media for the mediaelement.js player. Removed windows media player support. |
| 13 |
* version 1.5.0 - 04/23/2016 - Removed pp_embed_quicktime function (Preventive measure due to security issues with Quicktime) and removed pp_embed_swf, and show embed function enhanced to toggle. |
| 14 |
* version 1.4.0 - 09/08/2015 - Removed the pp_flashembed function (we are no longer using flash for fallback). |
| 15 |
* version 1.3.0 - 02/18/2011 - Adding HTML5 audio/video tags if format possibly supported around default video embed. |
| 16 |
* version 1.2.0 - 07/20/2009 - Major rewrite, we're now replying less upon this javascript to make way for flexibility for adding future players. |
| 17 |
* version 1.1.3 - 03/23/2009 - Added code to support FlowPlayer v3. |
| 18 |
* version 1.1.2 - 03/04/2009 - Added options to set the width for audio, width and height for video. |
| 19 |
* version 1.1.1 - 12/22/2008 - Minor change to support Windows Media in Firefox. Includes link to preferred Firefox Windows Media Player plugin. |
| 20 |
* version 1.1.0 - 11/25/2008 - Major re-write, object now stored in this include file, auto play is no longer a member variable and is determined by function call. |
| 21 |
* version 1.0.3 - 11/02/2008 - Added option for playing quicktime files in an intermediate fashion with an image to click to play. |
| 22 |
* version 1.0.2 - 07/26/2008 - Fixed pop up player bug caused by v 1.0.1 |
| 23 |
* version 1.0.1 - 07/28/2008 - fixed flow player looping playback, flash player no longer loops. |
| 24 |
* version 1.0.0 - 07/26/2008 - initial release |
| 25 |
* Minified with https://javascript-minifier.com/ |
| 26 |
*/ |
| 27 |
|
| 28 |
|
| 29 |
function powerpress_show_embed(id) |
| 30 |
{ |
| 31 |
if( document.getElementById('powerpress_embed_'+id) ) { |
| 32 |
if( document.getElementById('powerpress_embed_'+id).style.display == 'block' ) { |
| 33 |
document.getElementById('powerpress_embed_'+id).style.display = 'none'; |
| 34 |
} else { |
| 35 |
document.getElementById('powerpress_embed_'+id).style.display = 'block'; |
| 36 |
document.getElementById('powerpress_embed_'+id +'_t').select(); |
| 37 |
} |
| 38 |
} |
| 39 |
return false; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
Insert embed for H.264 mp4 video, with fallback to WebM |
| 44 |
|
| 45 |
@div - specific div to insert embed into |
| 46 |
@media_url - URL of media file to play |
| 47 |
@width - width of player |
| 48 |
@height - height of player |
| 49 |
@webm_media_url - Alternative WebM media URL |
| 50 |
*/ |
| 51 |
function powerpress_embed_html5v(id,media_url,width,height,webm_media_url) |
| 52 |
{ |
| 53 |
if( document.getElementById('powerpress_player_'+id) ) |
| 54 |
{ |
| 55 |
var poster = ''; |
| 56 |
if( document.getElementById('powerpress_player_'+id).getElementsByTagName ) { |
| 57 |
var images = document.getElementById('powerpress_player_'+id).getElementsByTagName('img'); |
| 58 |
if( images.length && images[0].src ) |
| 59 |
poster = images[0].src; |
| 60 |
} |
| 61 |
|
| 62 |
var contentType = 'video/mp4'; // Default content type |
| 63 |
if( media_url.indexOf('.webm') > -1 ) |
| 64 |
contentType = 'video/webm'; |
| 65 |
if( media_url.indexOf('.ogg') > -1 || media_url.indexOf('.ogv') > -1 ) |
| 66 |
contentType = 'video/ogg'; |
| 67 |
|
| 68 |
var v = document.createElement("video"); |
| 69 |
var html5 = false; |
| 70 |
if( !!v.canPlayType ) { |
| 71 |
var status = v.canPlayType(contentType); |
| 72 |
if( status == 'probably' || status == 'maybe' ) { |
| 73 |
html5 = true; |
| 74 |
} |
| 75 |
else if( webm_media_url ) |
| 76 |
{ |
| 77 |
status = v.canPlayType('video/webm'); |
| 78 |
if( status == 'probably' || status == 'maybe' ) { |
| 79 |
html5 = true; |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
if( html5 ) { |
| 85 |
var s = document.createElement('source'); |
| 86 |
v.width = width; v.height = height; v.controls = true; |
| 87 |
if( poster ) v.poster = poster; |
| 88 |
s.src = media_url; s.type = contentType; |
| 89 |
v.appendChild(s); |
| 90 |
if( webm_media_url ) { |
| 91 |
var s_webm = document.createElement('source'); |
| 92 |
s_webm.src = webm_media_url; s_webm.type = 'video/webm; codecs="vp8, vorbis"'; |
| 93 |
v.appendChild(s_webm); |
| 94 |
} |
| 95 |
|
| 96 |
document.getElementById('powerpress_player_'+id).innerHTML = ''; |
| 97 |
document.getElementById('powerpress_player_'+id).appendChild(v); |
| 98 |
v.play(); |
| 99 |
|
| 100 |
if( window.powerpress_resize_player ) |
| 101 |
powerpress_resize_player(); |
| 102 |
|
| 103 |
return false; // stop the default link from proceeding |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
return true; // let the default link to the media open... |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
Insert embed for audio, with fallback to flash (m4a/mp3/ogg) |
| 112 |
|
| 113 |
@div - specific div to insert embed into |
| 114 |
@media_url - URL of media file to play |
| 115 |
@width - width of player |
| 116 |
@height - height of player |
| 117 |
@webm_media_url - Alternative WebM media URL |
| 118 |
*/ |
| 119 |
function powerpress_embed_html5a(id,media_url) |
| 120 |
{ |
| 121 |
if( document.getElementById('powerpress_player_'+id) ) |
| 122 |
{ |
| 123 |
var poster = ''; |
| 124 |
if( document.getElementById('powerpress_player_'+id).getElementsByTagName ) { |
| 125 |
var images = document.getElementById('powerpress_player_'+id).getElementsByTagName('img'); |
| 126 |
if( images.length && images[0].src ) |
| 127 |
poster = images[0].src; |
| 128 |
} |
| 129 |
|
| 130 |
var contentType = 'audio/mpeg'; // Default content type |
| 131 |
if( media_url.indexOf('.m4a') > -1 ) |
| 132 |
contentType = 'audio/x-m4a'; |
| 133 |
if( media_url.indexOf('.ogg') > -1 || media_url.indexOf('.oga') > -1 ) |
| 134 |
contentType = 'audio/ogg'; |
| 135 |
|
| 136 |
var a = document.createElement("audio"); |
| 137 |
var html5 = false; |
| 138 |
if( !!a.canPlayType ) { |
| 139 |
var status = a.canPlayType(contentType); |
| 140 |
if( status == 'probably' || status == 'maybe' ) { |
| 141 |
html5 = true; |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
if( html5 ) { |
| 146 |
var s = document.createElement('source'); |
| 147 |
a.controls = true; |
| 148 |
s.src = media_url; s.type = contentType; |
| 149 |
a.appendChild(s); |
| 150 |
|
| 151 |
document.getElementById('powerpress_player_'+id).innerHTML = ''; |
| 152 |
document.getElementById('powerpress_player_'+id).appendChild(a); |
| 153 |
a.play(); |
| 154 |
return false; // stop the default link from proceeding |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
return true; // let the default link to the media open... |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
PowerPress on page load, make sure IE 9+/Edge use a custom flag for playback |
| 163 |
*/ |
| 164 |
function powerpress_onload() { |
| 165 |
var x = document.getElementsByTagName("audio"); |
| 166 |
for(i in x) { |
| 167 |
x[i].addEventListener("play", function(e) { |
| 168 |
var found = this.src.match( /media.(blubrry|rawvoice).(net|biz|com)\/[a-zA-Z_]{3,30}\/p\//i ); |
| 169 |
if( found.length > 0 ) { |
| 170 |
this.pause(); |
| 171 |
this.src = this.src.replace( found[0], found[0].replace('/p/', '/e/') ); |
| 172 |
this.load(); |
| 173 |
this.play(); |
| 174 |
} |
| 175 |
}, true); |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
if ( window.navigator.userAgent.match( /(MSIE|Edge|Trident)\//i ) !== null && window.addEventListener) { |
| 180 |
window.addEventListener('load', powerpress_onload, false); |
| 181 |
} |
| 182 |
|
| 183 |
function powerpress_stp(e) { |
| 184 |
e.preventDefault(); |
| 185 |
var ct = e.currentTarget; |
| 186 |
var p= ( ct.hasAttribute("data-pp-stp") ? ct.getAttribute("data-pp-stp") : 0 ), |
| 187 |
play =( ct.hasAttribute("data-pp-player") ? ct.getAttribute("data-pp-player") : '' ); |
| 188 |
if( play == '' ) return; |
| 189 |
var d = document.getElementById(play); |
| 190 |
if( d === null ) return; |
| 191 |
if( d.tagName == 'AUDIO' || d.tagName == 'MEDIAELEMENTWRAPPER' ) { |
| 192 |
d.currentTime=p; |
| 193 |
d.play(); |
| 194 |
} else if( d.tagName == 'IFRAME' ) { |
| 195 |
d.contentWindow.postMessage(p,'*'); |
| 196 |
} |
| 197 |
|
| 198 |
return false; |
| 199 |
} |