]> source.dussan.org Git - gitea.git/commitdiff
Serve audio files using HTML5 audio tag (#5221)
authorJonas Bröms <9416498+cez81@users.noreply.github.com>
Tue, 30 Oct 2018 02:17:26 +0000 (03:17 +0100)
committerLunny Xiao <xiaolunwen@gmail.com>
Tue, 30 Oct 2018 02:17:26 +0000 (10:17 +0800)
* Serve audio files using HTML5 audio tag

* Correct copy paste error

modules/base/tool.go
options/locale/locale_en-US.ini
routers/repo/view.go
templates/repo/view_file.tmpl

index 5b79a844ab352a7791f3af5f52601befc82c09e9..b069e5faee257d5b398f1a4744008b64f7589ebd 100644 (file)
@@ -576,6 +576,11 @@ func IsVideoFile(data []byte) bool {
        return strings.Index(http.DetectContentType(data), "video/") != -1
 }
 
+// IsAudioFile detects if data is an video format
+func IsAudioFile(data []byte) bool {
+       return strings.Index(http.DetectContentType(data), "audio/") != -1
+}
+
 // EntryIcon returns the octicon class for displaying files/directories
 func EntryIcon(entry *git.TreeEntry) string {
        switch {
index a0babf7a19865535a82a4bba5b12bb6afa313081..6f323415754b25bb26dc14fc183a3cffa5928ea1 100644 (file)
@@ -592,6 +592,7 @@ file_view_raw = View Raw
 file_permalink = Permalink
 file_too_large = The file is too large to be shown.
 video_not_supported_in_browser = Your browser does not support the HTML5 'video' tag.
+audio_not_supported_in_browser = Your browser does not support the HTML5 'audio' tag.
 stored_lfs = Stored with Git LFS
 commit_graph = Commit Graph
 
index 210eb9fe5ffb495aa434df16eaa779a7a6b7a724..657fe315a2a7316f58b9512859b48794a1254138 100644 (file)
@@ -264,6 +264,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
                ctx.Data["IsPDFFile"] = true
        case base.IsVideoFile(buf):
                ctx.Data["IsVideoFile"] = true
+       case base.IsAudioFile(buf):
+               ctx.Data["IsAudioFile"] = true
        case base.IsImageFile(buf):
                ctx.Data["IsImageFile"] = true
        }
index 6c37aab58ad409015a2c7a323a480364d38f1613..07d1075b13060218d69cb4403156649b9bc3c0d7 100644 (file)
                                                <video controls src="{{EscapePound $.RawFileLink}}">
                                                        <strong>{{.i18n.Tr "repo.video_not_supported_in_browser"}}</strong>
                                                </video>
+                                       {{else if .IsAudioFile}}
+                                               <audio controls src="{{EscapePound $.RawFileLink}}">
+                                                       <strong>{{.i18n.Tr "repo.audio_not_supported_in_browser"}}</strong>
+                                               </audio>
                                        {{else if .IsPDFFile}}
                                                <iframe width="100%" height="600px" src="{{AppSubUrl}}/vendor/plugins/pdfjs/web/viewer.html?file={{EscapePound $.RawFileLink}}"></iframe>
                                        {{else}}