我使用的是带有laravel 5.6和laravel-elfinder的TinyMce编辑器。我必须上传音频文件,但是编辑器无法识别音频文件,所以它通过调用video_template_callback来渲染为视频格式。因此,我将editor_config更改为:
var editor_config = {
selector: "textarea",
plugins: [
"image link lists textcolor imagetools table codesample textpattern media code"
],
video_template_callback: function(data){
console.log('call video');
return '<audio controls>' + '\n<source src="' + data.source1 + '"' + (data.source1mime ? ' type="' + data.source1mime + '"' : '') + ' />\n' + '</audio>';
},
audio_template_callback: function(data) {
console.log('call audio');
return '<audio controls>' + '\n<source src="' + data.source1 + '"' + (data.source1mime ? ' type="' + data.source1mime + '"' : '') + ' />\n' + '</audio>';
},
toolbar: "insertfile undo redo | styleselect | bold italic strikethrough | alignleft aligncenter alignright alignjustify | ltr rtl | bullist numlist outdent indent removeformat formatselect| link image media | emoticons charmap | code codesample | forecolor backcolor",
browser_spellcheck: true,
relative_urls: false,
remove_script_host: false,
media_poster: false,
media_filter_html: false,
file_browser_callback : function(field_name, url, type, win) {
tinymce.activeEditor.windowManager.open({
file: '<?= route('elfinder.tinymce4') ?>',// use an absolute path!
title: 'File Manager',
width: 900,
height: 450,
resizable: 'yes'
}, {
setUrl: function (url) {
win.document.getElementById(field_name).value = url;
}
});
},
setup:function(ed) {
ed.on('change', function(e) {
console.log('the content ', ed.getContent({ format: 'text' }));
});
}
};
[![tinymce.init(editor_config);][1]][1]测试此设置时,控制台仅输出“通话视频”。
发布于 2018-08-01 22:11:05
在当前版本的TinyMCE (4.8.1)中,如果你查看媒体插件的代码,你会看到如下所示的部分:
if (data.type === 'iframe') {
return getIframeHtml(data);
} else if (data.source1mime === 'application/x-shockwave-flash') {
return getFlashHtml(data);
} else if (data.source1mime.indexOf('audio') !== -1) {
return getAudioHtml(data, audioTemplateCallback);
} else if (data.type === 'script') {
return getScriptHtml(data);
} else {
return getVideoHtml(data, videoTemplateCallback);
}为了让某些东西作为音频被触发,它的mime类型需要包含字符串audio。如果所有其他测试都失败,则将其视为视频,因此我猜测该文件上的mime类型不包含字符串audio。
https://stackoverflow.com/questions/51624750
复制相似问题