Browser Audio js execute question

Discussion and feedback on Construct 2

Post » Sun Jun 12, 2016 5:19 pm

im currently playing audio files with browser

by using the bellow execution

"var aud = new Audio();
aud.src = '"&FileChooser.FileURLAt(0)&"';
aud.play();
"

everytime i import a new song it plays over the old one and sound duplicates


i tried using this "sound.pause();
sound.currentTime = 0;
" before i play a new audio but if i do that the global volume stops and the audio files aren't heard anymore

is there a way when i load a new song to stop the old song? i know i have to add a tag or name to the object but my skills are really poor on js.
B
70
S
20
G
67
Posts: 1,311
Reputation: 42,293

Post » Mon Jun 13, 2016 10:37 am

Why not just use the Audio plugin?
Scirra Founder
B
387
S
229
G
87
Posts: 24,245
Reputation: 192,160

Post » Mon Jun 13, 2016 4:24 pm

Ashley wrote:Why not just use the Audio plugin?




the project im working on(to kill my time and make something cool using C2 and Q3D) requires mp3/ogg/wave audio formats to be played... but users after i finish the project wont sit to convert to .ogg or any other format.. they will want to import a mp3 file directly since its the most common format on internet ...

i have a combination of filechooser and browser js snippet to play any audio format and read a song pcm data

which gives me a full preloaded waveform of any audio format...

but i cant add the audio analyser effect to it since the audio plugin is not playing that song but a new audio object that i made in the browser...

so now i need to get a js execution and basically reinvent everything to work around the audio plugin inability of playing mp3's and read the full waveform before playing the audio file in this case the music files that users wold choose to import.

all this wold be avoided if audio plugin could play mp3's alone with the other formats :) but at the moment it doesn't so i have to mash potato my brain and ask for forum help hehe :P

the audio plugin works perfect for the rest of the project... but mp3s and pcm data is the main game (ex of gameplay : audiosurf)

with the help of R0j0Hound i have the bellow capx...

which i adapted to work with the Q3d and i have a pretty close simulation as audiosurf... just now im missing the analyser effect which wold give me the beats reading while playing and ability to use those as speed boosting and notes/blocks spawning.

its a pretty easy project ... but gives me headaches since im a bit more clumsy then normal people with js.
capx: import any audio format and create a linear waveform - doesn't require custom plugins.


now since i explained what im doing...

the main audio js execution i need.. is for me to stop the audio playing... if i import a new song in the above capx .... for that i know i need a tag or name for each audio object i create... or i could destroy the audio object of the previews song and then create a new one when a new file is imported. ... or i can change the source... but for that i need to stop creating a new audio ... and that i have no clue how to do..
but as i said above... my js skills are similar to a preschool kid assembling puzzles.

as for the audio analyser its not a problem... i can calculate the length of each waveform line and convert it to a fictional speed when player is in proximity creating the illusion of speed boosting on beat.
B
70
S
20
G
67
Posts: 1,311
Reputation: 42,293

Post » Mon Jun 13, 2016 5:25 pm

You can probably find the blog post by ashley about the audio formats supported by C2 and why. It's mainly due to the need to be able to convert the audio to multiple formats so the audio is playable everywhere. Mp3 has licencing stuff associated with it's file format when reading/writing it so that's why it might not be suggested. Different browsers support playback of different formats as listed here:
https://developer.mozilla.org/en-US/doc ... ia_formats

In actuality all I think you're looking for is the ability to play a sound from an url with the audio plugin. So a feature request perhaps?
B
91
S
31
G
102
Posts: 5,231
Reputation: 67,248

Post » Mon Jun 13, 2016 8:06 pm

@r0j0hound

yea the formats post i read it and remember the reasons about the mp3 licensing which i agree they are pretty high and i understand the inconvenience ... but a link playing request i guess wold solve it :D
B
70
S
20
G
67
Posts: 1,311
Reputation: 42,293


Return to Construct 2 General

Who is online

Users browsing this forum: paradine and 2 guests