Skip to content

Commit db30d6d

Browse files
cez81lunny
authored andcommitted
Serve audio files using HTML5 audio tag (#5221)
* Serve audio files using HTML5 audio tag * Correct copy paste error
1 parent 735b12e commit db30d6d

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

modules/base/tool.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,11 @@ func IsVideoFile(data []byte) bool {
576576
return strings.Index(http.DetectContentType(data), "video/") != -1
577577
}
578578

579+
// IsAudioFile detects if data is an video format
580+
func IsAudioFile(data []byte) bool {
581+
return strings.Index(http.DetectContentType(data), "audio/") != -1
582+
}
583+
579584
// EntryIcon returns the octicon class for displaying files/directories
580585
func EntryIcon(entry *git.TreeEntry) string {
581586
switch {

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ file_view_raw = View Raw
592592
file_permalink = Permalink
593593
file_too_large = The file is too large to be shown.
594594
video_not_supported_in_browser = Your browser does not support the HTML5 'video' tag.
595+
audio_not_supported_in_browser = Your browser does not support the HTML5 'audio' tag.
595596
stored_lfs = Stored with Git LFS
596597
commit_graph = Commit Graph
597598

routers/repo/view.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
264264
ctx.Data["IsPDFFile"] = true
265265
case base.IsVideoFile(buf):
266266
ctx.Data["IsVideoFile"] = true
267+
case base.IsAudioFile(buf):
268+
ctx.Data["IsAudioFile"] = true
267269
case base.IsImageFile(buf):
268270
ctx.Data["IsImageFile"] = true
269271
}

templates/repo/view_file.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
<video controls src="{{EscapePound $.RawFileLink}}">
5656
<strong>{{.i18n.Tr "repo.video_not_supported_in_browser"}}</strong>
5757
</video>
58+
{{else if .IsAudioFile}}
59+
<audio controls src="{{EscapePound $.RawFileLink}}">
60+
<strong>{{.i18n.Tr "repo.audio_not_supported_in_browser"}}</strong>
61+
</audio>
5862
{{else if .IsPDFFile}}
5963
<iframe width="100%" height="600px" src="{{AppSubUrl}}/vendor/plugins/pdfjs/web/viewer.html?file={{EscapePound $.RawFileLink}}"></iframe>
6064
{{else}}

0 commit comments

Comments
 (0)