SDK Question program playing of mp3

JMW

Aspiring Addon Developer
Joined
Aug 5, 2008
Messages
670
Reaction score
89
Points
43
Location
Happy Wherever
Is it possible (if so how) to program the playing of an mp3 from a .dll
Want it to start playing after a set period of time - say 2 mins.
 
I cannot help with an mp3 from a dll, but I have been playing .ogg files from a lua script, completely independent from OrbiterSound, using proteaAudio.

Very easy to use and it's excellent for playing audio from real missions in an Orbiter scenario, exactly at the time you want.
You only have to convert the mp3 file to .ogg (For that, I use audacity).

If it is something that interests you, I can post the details and a couple of scripts.
 
Well, there must be a way to "hard encode" the mp3 file and then decode it from within the dll... that's how embedded resources works in .NET IIRC.
 
Thanks,
It would be another way to go.
Please post 'em and I'll give it a try.
 
Once you download proteAudio from the link in my previous post, place the proteaAudio_lua_090204 directory in your Orbiter folder.

-Open the folder, copy the ProAudioRT.dll and lua51.dll and paste them in your $Orbiterroot directory.

-Create an Ogg folder in the Sound folder

-Convert your mp3 to ogg and place it in $Orbiterroot\Sound\Ogg\

-Make (an empty) playsound.lua file and place it in the $Orbiterroot\Script\ folder.

Copy the lines below and paste them in the .lua file you just created.
(I added comments, so everything should be clear).

Code:
--link to player or exit if it doesn't exist
require("proAudioRt")
if not proAudio.create() then os.exit(1) end
sound = proAudio.sampleFromFile("Sound/Ogg/yoursound.ogg")--load the sound.
--yoursound is the name of the ogg file. Don't forget the extension.

sim_t = oapi.get_simtime()
play_t = 120 --number of seconds you want the file to start playing after scenario start
duration = proAudio.sampleProperties(sound) --audio file duration in seconds
play = 0 --player counter

while sim_t < (duration+play_t) do
  sim_t = oapi.get_simtime()
  if sim_t > play_t then
     play = play +1
     if play == 1 then --play the sound
        proAudio.soundPlay(sound) 
     end
     if play > 2 then --stop the counter
        play = 2 
     end 
  end 
  proc.skip()
  if sim_t > (duration + play_t)  then --if the simtime is > sound+wait close the player
     proAudio.destroy() 
  end
end --close the script

I am using a play counter, because sometimes at high framerates you cannot use "if sim_t == 120 then...", because the simtime may jump from 119.999 to 120.001

In your scenario file you need to add this line
Code:
Script playsound
under the date, between the BEGIN_ENVIRONMENT - END_ENVIRONMENT lines.

Hope this helps,
:cheers:
 
I've already said this in other occasions and I"m gonna say it again:
this community ROCKS and I'm constantly blown away by its endless skills!!!
 
Hi (esp dgatsoulis)
This script works perfectly -
But.
How can I play another -ogg file after 140 seconds?

I've tried numerous things - adding another section to the script - writing another seperate script under another title, starting after the first.
Nothing works for me. (won't post 'em cos will be too obvious I'm punting around in the dark.)

Thought it should be straightforward, but..........:shrug::shrug:
 
This should do it.

Code:
require("proAudioRt")
if not proAudio.create() then os.exit(1) end --get the player or exit if it doesn't exist

sound1 = proAudio.sampleFromFile("Sound/Ogg/yoursound1.ogg")
sound2 = proAudio.sampleFromFile("Sound/Ogg/yoursound2.ogg")
--load all the sounds at the start of the scenario
 
sim_t = oapi.get_simtime()
play_t1 = 120  -- number of seconds in simulation to play sound1 
play_t2 = 140  -- number of seconds in simulation to play sound2 
play1 = 0 --counter for sound1
play2 = 0 --counter for sound2

--[[in the next variable, replace x with the biggest value that follows this rule: (sound duration + play_t)
Example:
Lets say sound1 is 300 seconds long and it starts at 120. The total time for that is 420 
Lets say sound2 is  60 seconds long and it starts at 140. The total time for that is 200
You must use the biggest value (420) for the total_t]]--

total_t = x --replace x with the longest total_t

while sim_t < total_t do
 sim_t = oapi.get_simtime()
 if sim_t > play_t1 then 
    play1 = play1 +1
    if play1 == 1 then
       proAudio.soundPlay(sound1) 
	end
    if play1 > 2 then 
	   play1 = 2
    end
 end
 if sim_t > play_t2 then 
    play2 = play2 +1
    if play2 == 1 then
       proAudio.soundPlay(sound2) 
	end
    if play2 > 2 then 
	   play2 = 2
    end
 end 
 proc.skip()
 if sim_t > total_t then
    proAudio.destroy()
 end 
end

I am using "total_t" as the condition that unloads the sounds and closes the script. You can easily add a condition to check which is the longest, but it could get more complicated if you add more sounds. To simplify this, check beforehand which is the longest (sound file duration + wait time) and use that as the total_t variable.
 
It might not be my business, but is there a specific reason you don't want to use OrbiterSound? It's a well-done and easy to use plugin that most Orbinauts already have. :tiphat:
 
For me, it's cos OrbiterSound4 won't load a .wave above 8mb - files I want to play are 36mb and 41mb so need another method.
This script is perfect.
 
Also, you cannot overlap mp3s in OrbiterSound. Either you are playing one file or you are playing another file. ProteAudio has no such restrictions. You can simultaneously play as many files as your memory allows you to.

--Edit: :facepalm: of course you can play wav files...
 
And finally, Orbiter Sound has nothing to help for lua scripts.
That maybe good for interactive tutorials or for challenges design ! Like "Ermagherd, you are too slow ! And look at all this burnt fuel !" :lol:
 
I am only mentioning them because in addition to the usual script I am using the proteaAudio to play various sounds when certain conditions have been met. (either failures or successes).
 
I am only mentioning them because in addition to the usual script I am using the proteaAudio to play various sounds when certain conditions have been met. (either failures or successes).

Yeah, I saw that, the one time I installed the Mars landing challenge ...
Okay, challenge accepted, let's do it !
 
Back
Top