Issue with music not playing

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Lucyy
Citizen
Posts: 51
Joined: Thu Oct 15, 2015 6:57 am
Contact:

Issue with music not playing

Post by Lucyy »

Hi! I'm trying to play music in my game but so far nothing is playing regardless of what audio format I try to use.

I've attached a minimal .love file if someone could help me out

main.lua

Code: Select all

Sound = require("lib.sound")

function love.load()
	Sound:init("bg", "assets/sounds/bg.mp3", "static")
	Sound:play("bg")
end
lib/sound.lua

Code: Select all


local Sound = {active = {}, source = {}}

function Sound:init(id, source, soundType)
   assert(self.source[id] == nil, "Sound with that ID already exists!")

   if type(source) == "table" then
      self.source[id] = {}
      for i=1, #source do
         self.source[id][i] = love.audio.newSource(source[i], soundType)
      end
   else
      self.source[id] = love.audio.newSource(source, soundType)
   end
end

function Sound:clean(id)
   self.source[id] = nil
end

function Sound:play(id, channel, volume, pitch, loop)
   local source
   if type(Sound.source[id]) == "table" then
      source = Sound.source[id][math.random(1, #Sound.source[id])]
   else
      source = Sound.source[id]
   end

   local channel = channel or "default"
   local clone = source:clone()
   clone:setVolume(volume or 1)
   clone:setPitch(pitch or 1)
   clone:setLooping(loop or false)
   clone:play()

   if Sound.active[channel] == nil then
      Sound.active[channel] = {}
   end
   table.insert(Sound.active[channel], clone)

   return clone
end

function Sound:setVolume(channel, volume)
   assert(Sound.active[channel] ~= nil, "Channel does not exist")
   for k,sound in pairs(Sound.active[channel]) do
      sound:setVolume(volume)
   end
end

function Sound:setPitch(channel, pitch)
   assert(Sound.active[channel] ~= nil, "Channel does not exist")
   for k,sound in pairs(Sound.active[channel]) do
      sound:setPitch(pitch)
   end
end

function Sound:stop(channel)
   assert(Sound.active[channel] ~= nil, "Channel does not exist!")
   for k, sound in pairs(Sound.active[channel]) do
      sound:stop()
   end
end

function Sound:update()
   for k, channel in pairs(Sound.active) do
      if channel[1] ~= nil and not channel[1]:isPlaying() then
         table.remove(channel, 1)
      end
   end
end

return Sound
Attachments
audiotest.love
(5.29 MiB) Downloaded 143 times
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: Issue with music not playing

Post by GVovkiv »

Well, i definely can hear music
It's works fine, at least for me
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Issue with music not playing

Post by darkfrei »

I can hear your file too.

My minimal code:

Code: Select all

function love.load()
	source = love.audio.newSource("Ye-Olde-Pub_Looping.mp3", "stream") -- https://soundimage.org/fantasy-11/
	n_loops = 0
end

function love.update(dt)
	if not source:isPlaying( ) then
		n_loops = n_loops+1
		love.audio.play( source )
	end
end

function love.draw()
	love.graphics.print('Music by Eric Matyas\nYe-Olde-Pub_Looping: ' .. n_loops)
end
Attachments
music-Ye-Olde-Pub-01.love
(1.61 MiB) Downloaded 138 times
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Lucyy
Citizen
Posts: 51
Joined: Thu Oct 15, 2015 6:57 am
Contact:

Re: Issue with music not playing

Post by Lucyy »

darkfrei wrote: Mon Jun 21, 2021 7:54 am I can hear your file too.

My minimal code:

Code: Select all

function love.load()
	source = love.audio.newSource("Ye-Olde-Pub_Looping.mp3", "stream") -- https://soundimage.org/fantasy-11/
	n_loops = 0
end

function love.update(dt)
	if not source:isPlaying( ) then
		n_loops = n_loops+1
		love.audio.play( source )
	end
end

function love.draw()
	love.graphics.print('Music by Eric Matyas\nYe-Olde-Pub_Looping: ' .. n_loops)
end
This still isn't working for me either, could it have to do with me being on MacOS?
Lucyy
Citizen
Posts: 51
Joined: Thu Oct 15, 2015 6:57 am
Contact:

Re: Issue with music not playing

Post by Lucyy »

Update..! the audio works fine when I don't have my AirPods connected to my laptop, but the moment they're connected I cannot hear the music anymore
User avatar
togFox
Party member
Posts: 770
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Issue with music not playing

Post by togFox »

Are you listening to the airpods?

J/k

:)
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 58 guests