Skip to content

Commit

Permalink
use filetype of file to decode which extension to use
Browse files Browse the repository at this point in the history
  • Loading branch information
ajusa committed Jan 6, 2021
1 parent dd6e0f4 commit 3d94dd5
Show file tree
Hide file tree
Showing 2 changed files with 765 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/audio.moon
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
puremagic = require "lib/puremagic"
sound = {}
music = {}
filetype = {
"audio/x-aiff": "file.aiff"
"audio/x-flac": "file.flac"
"audio/mp4": "file.m4a"
"audio/x-matroska": "file.mka"
"audio/mpeg": "file.mp3"
"audio/vorbis": "file.ogg"
"audio/ogg": "file.ogg"
"audio/x-wav": "file.wav"
"audio/webm": "file.webm"
"audio/x-ms-wma": "file.wma"
}
load_source = =>
success, source = pcall(love.audio.newSource, @, "stream")
if success then return source
mime = puremagic.via_path(@)
original = love.filesystem.newFileData(@)
actual = love.filesystem.newFileData(original\getString(), filetype[mime])
return love.audio.newSource(actual, "stream")

on "save", =>
@music = {path: music.path}
@sound = {path: sound.path, n: sound.n}
Expand All @@ -16,19 +37,17 @@ exists = => @\sub(-1) != "~"
on "sound", =>
clear sound
if exists(@path) and @n != 0
success, file = pcall(love.audio.newSource, @path, "stream")
if success
file\setLooping(@n == -1)
file\play!
sound = {path: @path, :file, n: @n or 0}
file = with load_source(@path)
\setLooping(@n == -1)
\play!
sound = {path: @path, :file, n: @n or 0}
on "music", =>
clear music
if exists @path
success, file = pcall(love.audio.newSource, @path, "stream")
if success
file\setLooping(true)
file\play!
music = {path: @path, :file}
file = with load_source(@path)
\setLooping(true)
\play!
music = {path: @path, :file}
on "update", ->
if next(sound) and not sound.file\isPlaying! and sound.n > 1
sound.file\play!
Expand Down
Loading

0 comments on commit 3d94dd5

Please sign in to comment.