Can listen to tracks in the browser
This commit is contained in:
parent
69ddfd48e9
commit
2bcac6edd1
3 changed files with 52 additions and 0 deletions
|
|
@ -46,6 +46,33 @@ func LoadTracks(cfg *config.Config) (tracks []*Track, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (t *Track) Open() (*os.File, error) {
|
||||
return os.Open(t.Path)
|
||||
}
|
||||
|
||||
func (t *Track) Size() (int64, error) {
|
||||
if st, err := os.Stat(t.Path); err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
return st.Size(), err
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Track) ContentType() string {
|
||||
switch filepath.Ext(t.Path) {
|
||||
case ".flac":
|
||||
return "audio/flac"
|
||||
case ".mp3":
|
||||
return "audio/mpeg"
|
||||
case ".ogg":
|
||||
return "audio/ogg"
|
||||
case ".wav":
|
||||
return "audio/vnd.wav"
|
||||
}
|
||||
|
||||
return "application/octet-stream"
|
||||
}
|
||||
|
||||
func (t *Track) Rename(newName string) error {
|
||||
newPath := filepath.Join(filepath.Dir(t.Path), newName+filepath.Ext(t.Path))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue