php - 在Edit Laravel上观看视频

标签 php laravel audio video

嗨,我在这里遇到问题,如果有人可以帮助我。
我将图像保存在存储和编辑(更新) View ( Blade )上,原因是这样的:

<img src="{{url('/')}}/images/questions/{{ $question->id }}/medium/{{ $question->question_image }}" class="answer-image-create" id="question_image_box">

而且效果很好,因为图像可以像保存在存储文件夹中一样很好地保存,但是在音频和视频存储中以很多数字保存时,文件看起来像这样,例如videofile.mp4:
4944 3303 0000 0000 0000 fffb 9240 0000
0000 004b 0500 0000 0000 0960 a000 000b
2987 3c19 4880 0965 30e7 8329 1001 f19b
12cd dc1b 1006 8caf 8011 311b f804 9014
fed2 d805 814a 7db3 a165 04e9 07ff c2e6
0500 3204 4cc3 ffc9 c1c6 e813 eaff fcd0
66c8 b95c 8a11 434f fffc c8b9 271a b4d5
ffff f97d 2412 4190 4cdd 93ff ffff fd33
4410 2fa6 91c0 08fc 66c4 b377 06c4 01a3
2be0 044c 46fe 0124 053f b4b6 0160 529f
6ce8 5941 3a41 fff0 b981 400c 8113 30ff
f270 71ba 04fa bfff 3419 b22e 5722 8450..

我尝试过类似的方法来显示视频,但无法正常工作:
 <video width="320" height="240" preload="none" controls>
  <source src="{{url('/')}}/video/questions/{{ $question->id }}/original/{{ $question->question_video }}"  type="video/mp4">

任何的想法..?谢谢。

最佳答案

通过调整文件夹的结构来尝试以下操作:

您从以下路线获得视频:

Route::get('/videos/questions/{id}/original/{quetion_video}', [ 'as' => 'video', 'uses' => 'VideoController@viewVideo' ]);

在您的 Controller 中:
function viewVideo($id, $quetion_video)
{
    $filename = storage_path() . "/videos/questions".$id."/original/".$quetion_video.".mp4";
    $headers = array(
        'Content-type' => 'video/mp4'
    );

    return Response::make( file_get_contents($filename), 200, $headers);
}

在您看来:
<video width="320" height="240" controls>
        <source src="{{ route('getVideo', [ 'id => '$question->id, 'question_video' => $question->question_video ])  }}" type="video/mp4">
</video>

这是您必须做的事情的想法,您可以在此处获取示例和解释:

https://laracasts.com/discuss/channels/requests/how-to-let-user-play-audio-and-video-files-stored-in-directory-above-public

https://laracasts.com/discuss/channels/laravel/getting-video-from-storage-directory?page=0

https://laravel.io/forum/02-14-2016-how-read-uploaded-video-files-from-storage-directory

关于php - 在Edit Laravel上观看视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46955115/

相关文章:

php - Dream Weaver 表宽度

php - 如何对同名数据进行查询求和,但还是得到名字

php - 如何从 `<td>`内的文本添加分号然后通过ajax发送

php - 在 Laravel 5.4 中将外键 bigInteger 设置为 bigIncrements

mysql - Laravel 5.4 迁移 key 太长错误

mysql - 我可以在 laravel 数据库查询中使用 if 条件吗?

audio - modprobe : ERROR: could not insert 'snd_aloop' : No such device

来自 PHP 的 JavaScript 转义字符

matlab - Simulink 中的多 channel 音频输出

python - 循环多个变量以应用 sound.Sound() Psychopy 函数