No.4880

<script type="text/javascript">
///動画
$(document).ready(function() {
$('a[href$=".mp4"], a[href$=".mov"], a[href$=".webm"], a[href$=".ogg"], a[href$=".m4v"], a[href$=".avi"]').each(function() {
const $link = $(this);
const href = $link.attr('href');
// 拡張子に応じて適切なMIMEタイプを設定
const getVideoType = (ext) => {
const types = {
'mov': 'video/quicktime',
'mp4': 'video/mp4',
'webm': 'video/webm',
'ogg': 'video/ogg',
'm4v': 'video/mp4',
'avi': 'video/x-msvideo'
};
return types[ext.toLowerCase()] || '';
};
const fileExt = href.split('.').pop().toLowerCase();
const mimeType = getVideoType(fileExt);
const playerElement = `
<div class="video-container">
<video controls width="100%">
<source src="${href}" type="${mimeType}">
お使いのブラウザは動画の再生に対応していません。
</video>
</div>
`;
$link.replaceWith(playerElement);
});
});
</script>
バグってたら申し訳ないです
仕様
- 管理画面>設定>システム設定>【許可する画像の種類】で拡張子を入れると管理画面とQUICKPOSTからアップできるようになります(管理画面の画像の管理の画像欄には表示されません)
- URLの末尾に動画の拡張子がある場合、自動的にプレイヤーに変更されます
- サイズ変更はスクリプト内の<div class="video-container">~からどうぞ
- 5秒のところがサムネイルとして初期設定されているので、変えたい場合はMath.min(5, video.duration)の数値を変更してください