视频无法播放(规定为零时间),但所有控件均存在。 Forefox或Chrome ...说“找不到支持格式或MIME类型的视频”,我还尝试按照w3c.org规范在type属性中放入额外的数据。我在评论中包含了mp4的元数据。
<!-- video metadata: ---------------- error = GETID3_VERSION = 1.9.14-201706111222 FILESIZE = 15761394 FILEPATH = /home/sfcad/public_html/wp-content/uploads/2018/06 FILENAME = stump-trivia-50cent-wings.mp4 FILENAMEPATH = /home/sfcad/public_html/wp-content/uploads/2018/06/stump-trivia-50cent-wings.mp4 AVDATAOFFSET = 44 AVDATAEND = 15761394 FILEFORMAT = mp4 DATAFORMAT = mp4 CODEC = ISO/IEC 14496-3 AAC SAMPLE_RATE = 44100 CHANNELS = 2 BITS_PER_SAMPLE = 16 LOSSLESS = CHANNELMODE = stereo STREAMS 0 = Array DATAFORMAT = mpeg4 RESOLUTION_X = 1280 RESOLUTION_Y = 720 FOURCC = mp4v FRAME_RATE = 25 QUICKTIME ENCODING_TOOL = Array LANGUAGE 0 = English ENCODING = UTF-8 MIME_TYPE = video/mp4 HINTING = CONTROLLER = standard FTYP HIERARCHY = ftyp NAME = ftyp SIZE = 28 OFFSET = 0 SIGNATURE = isom UNKNOWN_1 = 512 FOURCC = isom FREE HIERARCHY = free NAME = free SIZE = 8 OFFSET = 28 MDAT HIERAapplication/x-shockwave-flashRCHY = mdat NAME = mdat SIZE = 15748861 OFFSET = 36 MOOV HIERARCHY = moov NAME = moov SIZE = 12497 OFFSET = 15748897 SUBATOMS = Array TIME_SCALE = 44100 DISPLAY_SCALE = 1 VIDEO RESOLUTION_X = 1280 RESOLUTION_Y = 720 FRAME_RATE = 25 FRAME_COUNT = 513 STTS_FRAMECOUNT 0 = 513 1 = 879 AUDIO CODEC = mp4 SAMPLE_RATE = 44100 CHANNELS = 2 BIT_DEPTH = 16 COMMENTS ENCODING_TOOL = Array ENCODING = UTF-8 PLAYTIME_SECONDS = 20.52 BITRATE = 6144775.82846 QUICKTIME ENCODING_TOOL = Array PLAYTIME_STRING = 0:21 -->
// functions.php
function videoshort($atts = []) {
// override attributes & normalize
$atts = array_change_key_case((array)$atts, CASE_LOWER);
$sfc_atts = shortcode_atts([
'src' => $atts['src'],
'type' => $atts['type'], // video/mp4
'style' => $atts['style'],
'controls' => $atts['controls'],
'class' => $atts['class'],
'id' => $atts['id'],
'width' => $atts['width'],
'height' => $atts['height'],
'autoplay' => $atts['autoplay'],
'loop' => null,
/** Access-Control-Allow-Origin: * **/
'crossorigin' => $atts['crossorigin'],
'preload' => $atts['preload'],
'poster' => $atts['poster'],
'playsinline' => null,
'muted' => null,
], $atts);
// html output
$html = "";
$html .= "<video ";
foreach($sfc_atts as $k => $v):
echo "<!-- {$k} = {$v} -->";
if ( !is_null($k) ):
if( !($k=="src") && !($k=="type" ) ):
$html .= " {$k}='{$v}' ";
endif;
endif;
endforeach;
$html .= "><source src='{$sfc_atts["src"]}' type='{$sfc_atts["type"]}' />";
$html .= "<i> ...no browser support...</i></video>";
// return html
return $html;
}add_shortcode( 'videoshort', 'videoshort' );
// shortcode
[videoshort
style="float:left;display:inline;"
src="http:\/\/7central.net\/wp-content\/themes\/Avada\/assets\/videos\/stump-trivia-50cent-wings.mp4"
width="267" height="150"
controls="1" id="videogif1"
class="seven-central-entertainment-float-left-responsive"
preload="metadata"
autoplay="on"
type="mp4"
poster="http:\/\/7central.net\/wp-content\/uploads\/2018\/06\/transparent.png"
crossorigin="anonymous"]
带有url的标记属性中的转义斜杠是为了防止短代码处理... 谢谢
答案 0 :(得分:0)
我将带有vlc的mp4转换为webm(VP8-VORBIS),并且可以正常工作。 webm适用于Chrome和Firefox,而不适用于野生动物园。我转换为mp4(mp4 H.264),在chrome和firefox中不起作用,但在野生动物园中起作用。我添加了2个短代码atts(src_web和type_webm),并为其设置了第二个源标签,因此现在根据浏览器,分发了正确的文件。我还添加了直接的javascript来关闭循环并静音(并显示其他数据...)
(function( $ ) {
// prevent looping on videos...
var firstDOMVideo = document.getElementsByTagName('video')[0];
console.log("video dimensions: video width - "+firstDOMVideo.videoWidth+" video height - "+firstDOMVideo.videoHeight);
console.log("actual video dimensions: video width - "+firstDOMVideo.width+" video height - "+firstDOMVideo.height);
if (typeof firstDOMVideo.loop == 'boolean') firstDOMVideo.loop = false;
if (typeof firstDOMVideo.muted == 'boolean') firstDOMVideo.muted = false;
if (typeof firstDOMVideo.autoplay == 'boolean') firstDOMVideo.autoplay = true;
// first video in the DOM has ended... ( getElementsByTagName('video')[0] )
// bug fix in Safari
firstDOMVideo.addEventListener('ended', function(e){
firstDOMVideo.pause();
}, false);
for(var types = ['mp4','webm'], i = 0; i < types.length; i ++){
if(/(maybe|proba.addEventListenerbly)/.test(firstDOMVideo.canPlayType('video/' + types[i]))) console.log("supports : video/" + types[i]+" ");
}
firstDOMVideo.addEventListener("timeupdate", function(e){
console.log("total time = ", firstDOMVideo.duration/60+ " seconds");
}, false);
//firstDOMVideo.play();
})();