Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: Specific Music or Soundtacks in mission?  (Read 4227 times)

WarStalkeR

  • Captain
  • ****
  • Posts: 343
  • Per Aspera Ad Astra!
    • View Profile
Specific Music or Soundtacks in mission?
« on: March 31, 2012, 09:19:29 AM »

Is this possible to add special music or soundtrack to play during a mission?
(Its question more for you Alex)
« Last Edit: March 31, 2012, 09:49:25 AM by WarStalkeR »
Logged

"Happiness for everybody, freely, and let no one to leave unhappy!" (c) Strugatsky Brothers
Independent Defense Force is here! And they already in Sector Xplo.

Psiyon

  • Admiral
  • *****
  • Posts: 772
  • Trippy
    • View Profile
Re: Specific Music or Soundtacks in mission?
« Reply #1 on: March 31, 2012, 09:58:27 AM »

Alex said that it wasn't possible when I asked him before.
Logged

WarStalkeR

  • Captain
  • ****
  • Posts: 343
  • Per Aspera Ad Astra!
    • View Profile
Re: Specific Music or Soundtacks in mission?
« Reply #2 on: March 31, 2012, 10:24:38 AM »

Alex said that it wasn't possible when I asked him before.
Probably for now. But you can actually put your music as ogg file in to sound.json... But probably function itself is missing or still not added...
Logged

"Happiness for everybody, freely, and let no one to leave unhappy!" (c) Strugatsky Brothers
Independent Defense Force is here! And they already in Sector Xplo.

WarStalkeR

  • Captain
  • ****
  • Posts: 343
  • Per Aspera Ad Astra!
    • View Profile
Re: Specific Music or Soundtacks in mission?
« Reply #3 on: March 31, 2012, 10:57:39 AM »

Tried now to create MusicPlayer.java:
Code
package data.scripts.world;

import sun.audio.*;
import java.io.*;

public class MusicPlayer {

    private String filename;

    public MusicPlayer(String filename) {
        this.filename = filename;
    }

    public void play() {
        try {
                InputStream in = new FileInputStream(filename);
                AudioStream as = new AudioStream(in);
                AudioPlayer.player.start(as);

        } catch (IOException e) {
                e.printStackTrace();
        }          
    }
}

Got this error:
Code
17665 [Thread-6] ERROR com.fs.starfarer.combat.String  - java.lang.RuntimeException: Error compiling [data.scripts.world.MusicPlayer]
java.lang.RuntimeException: Error compiling [data.scripts.world.MusicPlayer]
at com.fs.starfarer.loading.scripts.ScriptStore$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.SecurityException: File access and reflection are not allowed to scripts.
at com.fs.starfarer.loading.scripts.B.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.codehaus.janino.ClassLoaderIClassLoader.findIClass(ClassLoaderIClassLoader.java:83)
at org.codehaus.janino.IClassLoader.loadIClass(IClassLoader.java:158)
at org.codehaus.janino.IClassLoader.loadIClass(IClassLoader.java:124)
at org.codehaus.janino.UnitCompiler.loadFullyQualifiedClass(UnitCompiler.java:8729)
at org.codehaus.janino.UnitCompiler.importTypeOnDemand(UnitCompiler.java:7616)
at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java:4574)
at org.codehaus.janino.UnitCompiler.access$10300(UnitCompiler.java:104)
at org.codehaus.janino.UnitCompiler$17.visitReferenceType(UnitCompiler.java:4442)
at org.codehaus.janino.Java$ReferenceType.accept(Java.java:2020)
at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:4476)
at org.codehaus.janino.UnitCompiler.getLocalVariable(UnitCompiler.java:1607)
at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2226)
at org.codehaus.janino.UnitCompiler.access$3700(UnitCompiler.java:104)
at org.codehaus.janino.UnitCompiler$7.visitLocalVariableDeclarationStatement(UnitCompiler.java:2141)
at org.codehaus.janino.Java$LocalVariableDeclarationStatement.accept(Java.java:1771)
at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2144)
at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2158)
at org.codehaus.janino.UnitCompiler.access$2700(UnitCompiler.java:104)
at org.codehaus.janino.UnitCompiler$7.visitBlock(UnitCompiler.java:2129)
at org.codehaus.janino.Java$Block.accept(Java.java:1395)
at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2144)
at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2200)
at org.codehaus.janino.UnitCompiler.access$3400(UnitCompiler.java:104)
at org.codehaus.janino.UnitCompiler$7.visitTryStatement(UnitCompiler.java:2136)
at org.codehaus.janino.Java$TryStatement.accept(Java.java:1592)
at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2144)
at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2105)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1946)
at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:789)
at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:770)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:464)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:357)
at org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java:312)
at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:770)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:319)
at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:288)
at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:203)
at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:157)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 2 more
23616 [Thread-6] INFO  com.fs.profiler.Profiler  - ID     Calls   Duration    Percent
23617 [Thread-6] INFO  com.fs.profiler.Profiler  - --------------------------------

Tried to use audio file that completely converted to class (Jawa.java - you can download it)...

Got same error:
Code
17267 [Thread-6] ERROR com.fs.starfarer.combat.String  - java.lang.RuntimeException: Error compiling [data.scripts.world.Jawa]
java.lang.RuntimeException: Error compiling [data.scripts.world.Jawa]
at com.fs.starfarer.loading.scripts.ScriptStore$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.SecurityException: File access and reflection are not allowed to scripts.
at com.fs.starfarer.loading.scripts.B.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.codehaus.janino.ClassLoaderIClassLoader.findIClass(ClassLoaderIClassLoader.java:83)
at org.codehaus.janino.IClassLoader.loadIClass(IClassLoader.java:158)
at org.codehaus.janino.ReflectionIClass.classToIClass(ReflectionIClass.java:305)
at org.codehaus.janino.ReflectionIClass.classesToIClasses(ReflectionIClass.java:320)
at org.codehaus.janino.ReflectionIClass.getInterfaces2(ReflectionIClass.java:116)
at org.codehaus.janino.IClass.getInterfaces(IClass.java:361)
at org.codehaus.janino.UnitCompiler.getIMethods(UnitCompiler.java:6637)
at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:6575)
at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:6488)
at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:3429)
at org.codehaus.janino.UnitCompiler.access$6300(UnitCompiler.java:104)
at org.codehaus.janino.UnitCompiler$11.visitMethodInvocation(UnitCompiler.java:2869)
at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:2831)
at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:2890)
at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:3897)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1637)
at org.codehaus.janino.UnitCompiler.access$1700(UnitCompiler.java:104)
at org.codehaus.janino.UnitCompiler$5.visitReturnStatement(UnitCompiler.java:877)
at org.codehaus.janino.Java$ReturnStatement.accept(Java.java:1803)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:888)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1740)
at org.codehaus.janino.UnitCompiler.access$1200(UnitCompiler.java:104)
at org.codehaus.janino.UnitCompiler$5.visitTryStatement(UnitCompiler.java:872)
at org.codehaus.janino.Java$TryStatement.accept(Java.java:1592)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:888)
at org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:914)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1999)
at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:789)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:493)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:357)
at org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java:312)
at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:770)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:319)
at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:288)
at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:203)
at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:157)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 2 more
19657 [Thread-6] INFO  com.fs.profiler.Profiler  - ID     Calls   Duration    Percent
19657 [Thread-6] INFO  com.fs.profiler.Profiler  - --------------------------------

[attachment deleted by admin]
Logged

"Happiness for everybody, freely, and let no one to leave unhappy!" (c) Strugatsky Brothers
Independent Defense Force is here! And they already in Sector Xplo.

WarStalkeR

  • Captain
  • ****
  • Posts: 343
  • Per Aspera Ad Astra!
    • View Profile
Re: Specific Music or Soundtacks in mission?
« Reply #4 on: March 31, 2012, 10:59:27 AM »

Alex, Epic Battles need Epic Music ;D
Logged

"Happiness for everybody, freely, and let no one to leave unhappy!" (c) Strugatsky Brothers
Independent Defense Force is here! And they already in Sector Xplo.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Specific Music or Soundtacks in mission?
« Reply #5 on: March 31, 2012, 11:01:10 AM »

Yeah, this isn't going to work - there are some security checks in place to try to ensure mods don't do something *really bad* - like accidentally deleting the contents of your hard drive.

Nice try, though :) I'll see about adding a way for mods to get at files in a more sandboxed way in the future.
Logged

WarStalkeR

  • Captain
  • ****
  • Posts: 343
  • Per Aspera Ad Astra!
    • View Profile
Re: Specific Music or Soundtacks in mission?
« Reply #6 on: March 31, 2012, 12:19:02 PM »

Yeah, this isn't going to work - there are some security checks in place to try to ensure mods don't do something *really bad* - like accidentally deleting the contents of your hard drive.

Nice try, though :) I'll see about adding a way for mods to get at files in a more sandboxed way in the future.
We use sounds.json for audio and effects of weapons. Why don't use it for music too? And then just use PlayMusic(id of soundtack mapped in sounds.json)?
Logged

"Happiness for everybody, freely, and let no one to leave unhappy!" (c) Strugatsky Brothers
Independent Defense Force is here! And they already in Sector Xplo.

MrDavidoff

  • Captain
  • ****
  • Posts: 398
    • View Profile
Re: Specific Music or Soundtacks in mission?
« Reply #7 on: March 31, 2012, 12:37:58 PM »

Im just curious, what kind of music will they eventually put in the game  .. in the mean time.. I listen to imperial march loop  :D
Logged

WarStalkeR

  • Captain
  • ****
  • Posts: 343
  • Per Aspera Ad Astra!
    • View Profile
Re: Specific Music or Soundtacks in mission?
« Reply #8 on: April 01, 2012, 12:57:57 AM »

Im just curious, what kind of music will they eventually put in the game  .. in the mean time.. I listen to imperial march loop  :D
Alex don't have to add music itself, but it will be good if he will add function, that will allow you to start playing music in missions / campaign.
Logged

"Happiness for everybody, freely, and let no one to leave unhappy!" (c) Strugatsky Brothers
Independent Defense Force is here! And they already in Sector Xplo.