How do I link scripted audio to an Audio object?

0 favourites
  • 4 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I have written a radio mobile app which works great and plays the FM stations music which is being broadcast via 'broadcast radio'.

    The stream is basically the same as icecast/shoutcast and I believe is being broadcast as an mpeg.

    I am currently doing the following:

    Global string AudioURL = streaming.broadcast.radio/hitmixhigh

    let audio = new Audio(runtime.globalVars.AudioURL);

    audio.play();

    This works perfect and I can use script to play and pause the stream. However as its a mobile app it naturally loses focus or goes in to sleep mode after timing out or someone locking the phone.

    I can see that the Audio Object as a 'Play in background' option.

    Is there anyway of linking the script to the Audio object to get it play the MPEG audio stream?

    (Note that it is a stream and never downloads as it is constantly suppling more audio so the URL download will never end.)

    Any help would be appreciated.

    Adrian

  • Just to add I have made the new audio instance global so that each event can access it to say play and pause for example.

    let audio = new Audio(runtime.globalVars.AudioURL);

    runtime.globalVars.Player = audio;

    runtime.globalVars.Player.play();

    Ashley

  • Construct expects global variables to be strings, numbers or booleans. Don't assign objects to global variables or it will probably crash Construct.

    Construct's 'Play audio in background' just means 'don't deliberately pause all audio when going in to the background'. If you play audio with JavaScript then you are working with the browser directly, and Construct is not involved in when audio playback starts and stops.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi Ashley

    Thank you for your reply.

    It allows me to assigning the object as a global variable and I can reference it from each new event, so my pause resume button works perfectly, but I'm referencing it from the JavaScript to do this not construct.

    i.e.

    runtime.globalVars.Player.play();

    or

    runtime.globalVars.Player.pause();

    I am not adding a global variable in construct for it though, only in the JavaScript.

    If I add the global variable in construct, it stops working.

    Do you know if there is a way to make the audio object play the stream rather than doing any of the above?

    If its beyond it capabilities, is there a tutorial or something where I can look at modifying the plugin? and do I have access to modify the plugin and resave it?

    Thank you for the help.

    Kindest regards

    Adrian

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)