12345678910111213141516171819 |
- package services
- import (
- "github.com/tosone/minimp3"
- )
- func GetMP3PlayDuration(mp3Data []byte) (seconds int, err error) {
- dec, _, err := minimp3.DecodeFull(mp3Data)
- if err != nil {
- return 0, err
- }
- if dec.Kbps <= 0 {
- return 0, err
- }
-
- seconds = (len(mp3Data) - 128) * 8 / (dec.Kbps * 1000)
- return seconds, nil
- }
|