简体   繁体   English

如何显示图像,视频和音频从数据库到网页作为输出?

[英]How to display image, video and audio from db to web page as an output?

I don't know of this is possible but I am outputting image, audio and video files from my db using their directory and filenames. 我不知道这是可能的,但是我正在使用其目录和文件名从数据库中输出图像,音频和视频文件。 For example in db: 例如在db中:

Image:                    Audio:                           Video:

ImageFiles/tulips.png     AudioFiles/LadyintheNight.mp3    VideoFiles/training.mpeg

Below are the variables that each value from the db are stored in and outputted: 以下是数据库中每个值存储和输出的变量:

echo $dbImage;
echo $dbAudio;
echo $dbVideo;

So the output is simply: 所以输出很简单:

ImageFiles/tulips.png 
AudioFiles/LadyintheNight.mp3
VideoFiles/training.mpeg

But I want to do 2 things with these strings: 但是我想用这些字符串做两件事:

  • If I echo each value as a hyperlink, is there a way I can click on one of the links and either display the image, a player playing the audio or a player plaving the video in a separate page? 如果我将每个值都作为超链接回显,是否可以单击链接中的一个并显示图像,播放音频的播放器或将视频放在单独页面中的播放器?

  • If I echo $dbImage as an image tag value, it will display the url as an image. 如果我将$dbImage作为图像标签值回显,它将把URL显示为图像。 My question is though how can I display an audio or a video player so the user can see the audio/video and play it? 我的问题是,如何显示音频或视频播放器,以便用户可以观看音频/视频并进行播放?

I was thinking of something like JavaScript that creates an iframe for the video. 我在想像JavaScript这样的东西,可以为视频创建iframe。 This is only a simple example, but it will give you an idea. 这只是一个简单的示例,但是它将给您一个想法。 You can add fancy lightbox effects if you want, and for more compatibility it would be good to use at least 2 types of video formats, mp4 and ogv. 您可以根据需要添加精美的灯箱效果,并且为了获得更大的兼容性,最好使用至少两种类型的视频格式mp4和ogv。

$('<div id="VideoBackground"></div>').appendTo('body').css({
    opacity: 0.6, 
    position: 'fixed',
    top: 0,
    left: 0,
    width: '100%',
    'z-index':'999',
    'background-color': '#CCCCCC',
    height: $(window).height() + 'px'}).hide();
$('<div id="UpperElement"><iframe id="VideoFrame" frameborder="0" scrolling="no" style="width: 320px; height: 240px;"></iframe></div>').appendTo('#VideoBackground');
$('#UpperElement').css({
    'z-index':'1000',
    'margin':'0 auto',
    'width': '320px',
    'height': '240px'
});

document.getElementById('VideoFrame').onload = function() {
    $('#VideoFrame').contents().find('body').append('<video width="320" height="240" controls><source src="http://www.808.dk/pics/video/gizmo.mp4" type="video/mp4"><source src="http://www.808.dk/pics/video/gizmo.ogv" type="video/ogg">Your browser does not support the video tag.</video>');
}

$('#VideoBackground').show();
$('#UpperElement').show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM