Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

2 audio files on the same channel
Started by gudrutis1 Feb 29 2020 11:49 AM

5 replies to this topic

Best Answer roaminggamer , 29 February 2020 - 12:30 PM

Please note, the way you imply you're using show() and hide() is also wrong.

 

Those have will and did phases, so if you have code that affects the channel in:

  • scene 1 hide()
  • scene2 show()

You'll get this sequence:

  1. scene 1 will hide() - audio.stop()
  2. scene 2 will show() - audio.loadStream()
  3. scene 1 did hide() - audio.stop()
  4. scene 2 did show() - audio.loadStream()

If these all end up getting processed in the same frame, you may have varied results.  

 

In any case, you need to pay attention to the will and did phases of show()/hide().

 

https://docs.coronalabs.com/api/event/scene/show/phase.html

https://docs.coronalabs.com/api/event/scene/hide/phase.html

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

gudrutis1

[GLOBAL: userInfoPane.html]
gudrutis1
  • Enthusiast

  • 37 posts
  • Corona SDK

--main.lua

audio.reserveChannels(1)

 

 

--scene1

--In scene:create

bgMusic = audio.loadStream("audio1.mp3")

 
--In scene:show
audio.play(bgMusic, {channel=1})
   
--In scene:hide 
audio.stop(1) 
 
 
--scene2

-In scene:create

bgMusic = audio.loadStream("audio2.mp3")
 
--In scene:show
audio.play(bgMusic, {channel=1})
     
 
 
If I try to play 2 different audio files in the same scene on the same channel using play() stop() play() it does the work but not when I'm using composer and 2 scenes. Why is that? 

 

 



[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 809 posts
  • Corona SDK

You might have to dispose the audio for one of the scenes



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,666 posts
  • Corona SDK

  Best Answer

Please note, the way you imply you're using show() and hide() is also wrong.

 

Those have will and did phases, so if you have code that affects the channel in:

  • scene 1 hide()
  • scene2 show()

You'll get this sequence:

  1. scene 1 will hide() - audio.stop()
  2. scene 2 will show() - audio.loadStream()
  3. scene 1 did hide() - audio.stop()
  4. scene 2 did show() - audio.loadStream()

If these all end up getting processed in the same frame, you may have varied results.  

 

In any case, you need to pay attention to the will and did phases of show()/hide().

 

https://docs.coronalabs.com/api/event/scene/show/phase.html

https://docs.coronalabs.com/api/event/scene/hide/phase.html


  • agramonte likes this

[TOPIC: post.html]
#4

gudrutis1

[GLOBAL: userInfoPane.html]
gudrutis1
  • Enthusiast

  • 37 posts
  • Corona SDK

That's it .I just needed to use scene phases differently. But the sequence by which scenes are executed is not clear to me.

 

Looks like scene 2 create() comes before scene 2 show() either is will or did. But the scene 2 create() also probably comes after previous scene 1 hide() will or did. How scene 1 did hide() can be executed at the same time as the scene 2 will show(). Where the scene create() stands here?



[TOPIC: post.html]
#5

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,666 posts
  • Corona SDK

If you want to work this out, just put print statements in all the right places on two scenes, then look at the logs to see what prints out.

 

Note: This info is also on the site, I just don't remember where, but I found the image which explains it by googling 'composer flowchart':

 

composer-flowchart.png


  • XeduR @Spyric likes this

[TOPIC: post.html]
#6

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,246 posts
  • Corona SDK

The flowchart and its accompanying tutorials and explanations can be found at https://docs.coronalabs.com/guide/system/composer/index.html


  • roaminggamer likes this


[topic_controls]
[/topic_controls]