Search Unity

Android Sound Latency Fix

Discussion in 'Assets and Asset Store' started by Catsknead, Apr 19, 2015.

  1. Catsknead

    Catsknead

    Joined:
    Dec 21, 2014
    Posts:
    10
    If you're developing mobile games for Android, you've probably noticed ridiculous sound delay on some devices.
    No more. With this plugin, your sounds will play almost immediately. Check out this demo video:


    Features:

    - Play in-game sounds without any delay on Android devices
    - Simultaneous playback of several sounds
    - All kinds of Android built-in audio file formats are supported
    - Plugin uses Android Sound Pool for managing and using sound files
    - Doesn't conflict with Unity sound system

    It works by issuing direct calls to the Android OS, bypassing everything that Unity has in its audio system. It means that sounds won't be affected by distance, Doppler, project volume settings etc, which is perfectly acceptable for most of the Android games. In our game, music is played by Unity and short sounds are managed by this plugin, with no issues.

    Usage is simple:
    - Send filename of sound and get its ID's with AudioCenter.loadSound(path_to_file) method
    - Play it with AudioCenter.playSound(sound_id) method
    - Unload it with AudioCenter.unloadSound(sound_id) method to save memory
    For more detailed instructions, refer to the .pdf, supplied with the plugin.

    Download it directly from our website: http://catsknead.me/static/plugin.zip

    In the archive you'll find .unitypackage, .pdf with detailed instructions, .java file, containing full source of the Android-side of the plugin and a test scene, in which you can compare two playback methods.
    If you see no sound delay in the provided example scene - you probably have a lucky device, try another one :)

    Coming to the Asset Store soon.
     
    mmonly, Marrt, blizzy and 1 other person like this.
  2. GCat

    GCat

    Joined:
    Jul 31, 2012
    Posts:
    167
    Thanks! should be useful
     
  3. BonyYousuf

    BonyYousuf

    Joined:
    Aug 22, 2013
    Posts:
    104
    Thank you so much :)
     
  4. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    This seems a nice solution.

    I'm trying to do this with accessing AudioCenter.cs with javascript.
    I imported the package and I have made a folder Assets/Resources/Sounds/ with the soundfile.
    I moved the file AudioCenter.cs to the folder Assets/Plugins and changed the line "public class AudioCenter" into "public class AudioCenter: MonoBehaviour"

    I have made the following javascript:

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. private var csScript: AudioCenter; //create a variable to access the C# script
    4. public var soundID: int;
    5.  
    6. function Start ()
    7. {
    8.     csScript = this.GetComponent(AudioCenter);
    9. }
    10.  
    11. function loadPluginSound ()
    12. {
    13.     soundID = csScript.loadSound("Resources/Sounds/Example.wav");
    14. }
    15.  
    16. function PlayExample ()
    17. {
    18.     csScript.playSound (soundID);
    19. }

    This is the file AudioCenter.cs:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class AudioCenter: MonoBehaviour
    5. {
    6.     #if UNITY_ANDROID && !UNITY_EDITOR
    7.     public static AndroidJavaClass unityActivityClass = new AndroidJavaClass( "com.unity3d.player.UnityPlayer" );
    8.     public static AndroidJavaObject activityObj = unityActivityClass.GetStatic<AndroidJavaObject>( "currentActivity" );
    9.     private static AndroidJavaObject soundObj = new AndroidJavaObject( "com.catsknead.androidsoundfix.AudioCenter", 1, activityObj, activityObj );
    10.    
    11.     public static void playSound( int soundId ) {
    12.         soundObj.Call( "playSound", new object[] { soundId } );
    13.     }
    14.    
    15.     public static int loadSound( string soundName ) {
    16.         return soundObj.Call<int>( "loadSound", new object[] { soundName } );
    17.     }
    18.    
    19.     public static void unloadSound( int soundId ) {
    20.         soundObj.Call( "unloadSound", new object[] { soundId } );
    21.     }
    22.     #else
    23.     public static void playSound( int soundId ) {
    24.         Debug.Log( "Play sound called: " + soundId.ToString() );
    25.     }
    26.    
    27.     public static int loadSound( string soundName ) {
    28.         Debug.Log( "Load sound called: " + soundName );
    29.         return 0;
    30.     }
    31.    
    32.     public static void unloadSound( int soundId ) {
    33.         Debug.Log( "Unload sound called: " + soundId.ToString() );
    34.     }
    35.     #endif
    36. }
    37.  
    I attached these two scripts to the gameobject and I created an Audio Source. I unchecked "3D Sound" in the Inspector.
    In my game I call the function PlayExample () but I don't hear anything.
    There are no errors and in the console I see: Load sound called: Resources/Sounds/example.wav and Play sound called: 0.

    I think I forgot something. What am I doing wrong?
     
  5. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    I found out that I don't have to access AudioCenter.cs with javascript. It's working fine now.
    But I have one question.
    What is this part of AudioCenter.cs doing?

    Code (CSharp):
    1.  public static AndroidJavaClass unityActivityClass = new AndroidJavaClass( "com.unity3d.player.UnityPlayer" );
    2.     public static AndroidJavaObject activityObj = unityActivityClass.GetStatic<AndroidJavaObject>( "currentActivity" );
    3.     private static AndroidJavaObject soundObj = new AndroidJavaObject( "com.catsknead.androidsoundfix.AudioCenter", 1, activityObj, activityObj );
    4.  
     
  6. Catsknead

    Catsknead

    Joined:
    Dec 21, 2014
    Posts:
    10
    Sorry for not replying. I'm not experienced with JS, so I can't tell what's wrong there, your code seems fine to me :(

    This part of the code prepares all the necessary Java objects for the plugin to use.
    First line retrieves the actual UnityPlayer of the game, second - gets the current activity object, third one creates an instance of the AudioCenter Java class (our plugin), with this number of streams and activity passed to the constructor.
    For some reason I've published plugin that was built from non-refactored code, that's why there are two activityObj passed, please ignore that... included source is the refactored one, though.

    Check out examples here: http://docs.unity3d.com/Manual/PluginsForAndroid.html

    Oh, and you don't need Audio Source or Audio Listener with this plugin.
     
  7. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    Thanks for reply!
    I'm totally not experienced with this Java stuff yet.
    Is it right that you need something from your website to make it work (third line)? So that you need an internet connection to make it work?
     
  8. Chambers_Zhao

    Chambers_Zhao

    Joined:
    Apr 23, 2015
    Posts:
    4
    If I want to play midi files instead of these sound files,how can I do?
     
  9. Catsknead

    Catsknead

    Joined:
    Dec 21, 2014
    Posts:
    10
    No, not at all! That's just a package name.

    All these formats should work, including midi:
    https://developer.android.com/guide/appendix/media-formats.html#core
     
  10. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    It's working great!
    Thanks Catsknead!
     
  11. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    One question.
    When I push the game to my Android device the sounds are perfect but when I play the game in the Unity editor, I don't hear the sounds anymore.
    Why is that?
     
  12. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    993
  13. fadden

    fadden

    Joined:
    Feb 11, 2015
    Posts:
    13
    I did some similar experiments.



    I've found that the latency varies significantly between devices. A simple demo with a bouncing ball that played a sound in the collider looked fine on various Nexus tablets, but was seriously off on my Moto X. So there's definitely a device-specific component, but the fact that you can get much better latency by side-stepping Unity suggests that it's possible for Unity to do better.

    (Demo project on github)
     
  14. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    520
    @sonicviz
    All your games have something to do with sound, did you manage to use this fix already? just curious...

    Strange how this is such an underdiscussed issue. The audio latency was the very first thing that i noted when i first tried my build on android.
     
  15. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    520
    I got it to work!

    Is there a way to manage certain parameters of the sounds? like volume etc.?
     
  16. Catsknead

    Catsknead

    Joined:
    Dec 21, 2014
    Posts:
    10
    Unfortunately, for now it totally relies on the system volume, so the only way to change it is to change the system volume through special permission. Users probably won't be happy with such intervention.
    We made our sounds more silent by opening them in Audacity and amplifying them by negative dB. If you have lots of files - you can use batch processing:
    • Open Audacity
    • File > Edit Chains
    • Remove everything
    • Insert "Amplify"
    • Edit parameter
    • OK
    • File > Apply chain > Apply to Files > Select them...
    It certainly is possible to change the volume of individual .play() calls, but for now we're really busy with porting our game to iOS and won't be able to update this plugin for a week or so... sources are open, everyone is welcome to tweak them :)
     
    Marrt likes this.
  17. mmonly

    mmonly

    Joined:
    Mar 25, 2015
    Posts:
    2
    help me alot, thanks you so much
    have a problems, it conflict with Ultimate Mobile plugin, i don't know how to fix
     
    Last edited: Jul 6, 2015
  18. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    520
    If anyone needs volume control, you could add those 2 overloads to the AudioCenter.java of Catsknead.and then it should work
    Code (CSharp):
    1. public void playSound( int soundID, float volume ){
    2.         if( ( !soundsSet.contains( soundId ) ) || ( soundId == 0 ) ) {
    3.             Log.e( "SoundPluginUnity", "File has not been loaded!" );
    4.             return;
    5.         }
    6.  
    7.         final int sKey = soundId;
    8.  
    9.         activity.runOnUiThread( new Runnable() {
    10.             public void run() {
    11.                  play( sKey, volume, volume, 1, 0, 1f );
    12.             }
    13.         } );
    14.      
    15.     }
    16.    
    17.     public void playSound( int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate ){
    18.        if( ( !soundsSet.contains( soundId ) ) || ( soundId == 0 ) ) {
    19.             Log.e( "SoundPluginUnity", "File has not been loaded!" );
    20.             return;
    21.         }
    22.  
    23.         final int sKey = soundId;
    24.  
    25.         activity.runOnUiThread( new Runnable() {
    26.             public void run() {
    27.                  play( sKey, leftVolume, rightVolume, priority, loop, rate );
    28.             }
    29.         } );
    30.     }

    I wasn't able to compile the .java to a jar because i have no tools installed for this, and the command line "javac" gives me errors.
     
  19. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    68
    I'm unable to play multiple sounds at the same time.
    When my character jumps and hits a coin the jump sound is immediately overridden by the coin sound :c
     
  20. theuncas

    theuncas

    Joined:
    Feb 21, 2015
    Posts:
    21
    Hello Saishy,
    can you post your code in order to help you..
    Your load, play (and unload if you use it)

    EDIT : What version of unity are you using ?

    Thx,
    David
     
  21. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    68
    void Awake() {
    GameInfo.instance = this;

    bigCoin = AudioCenter.loadSound("Resources/Sounds/big_coin_002.wav");
    coin = AudioCenter.loadSound("Resources/Sounds/coin_002.wav");
    attack = AudioCenter.loadSound("Resources/Sounds/destroy_001.wav");
    gameOver = AudioCenter.loadSound("Resources/Sounds/hurt_005.wav");
    jump = AudioCenter.loadSound("Resources/Sounds/jump_012.wav");
    }

    Sounds are played like this:

    AudioCenter.playSound(attack);

    Unity 5.1.2f1
     
  22. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    520
    The plugin is written in a way that only allows for a single simultaneous stream. You have to change the java file, allow for more streams and compile it to jar. Read the api of soundpool.
     
  23. theuncas

    theuncas

    Joined:
    Feb 21, 2015
    Posts:
    21

    "In addition to low-latency playback, SoundPool can also manage the number of audio streams being rendered at once. When the SoundPool object is constructed, the maxStreams parameter sets the maximum number of streams that can be played at a time from this single SoundPool. SoundPool tracks the number of active streams. If the maximum number of streams is exceeded, SoundPool will automatically stop a previously playing stream based first on priority and then by age within that priority. Limiting the maximum number of streams helps to cap CPU loading and reducing the likelihood that audio mixing will impact visuals or UI performance."

    You're right : http://developer.android.com/reference/android/media/SoundPool.html

    On the catsknead java class, we can see it's constructor :
    "public AudioCenter( int maxStreams, Activity activity )", so you have to modify maxStreams value

    maybe this line on AudioCenter.cs
    Code (CSharp):
    1. private static AndroidJavaObject soundObj = new AndroidJavaObject( "com.catsknead.androidsoundfix.AudioCenter", 1, activityObj, activityObj );
    2.    
     
    Last edited: Jul 23, 2015
  24. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    520
    True, it is the int:
    Code (CSharp):
    1.  
    2. public AudioCenter( int maxStreams, Activity activity )
    3.     {
    4.         super( maxStreams, AudioManager.STREAM_MUSIC, 0 );
    5.         this.activity = activity;
    6.  
    7.         setOnLoadCompleteListener( new OnLoadCompleteListener() {
    8.             @Override
    9.             public void onLoadComplete( SoundPool soundPool, int sampleId, int status ) {
    10.                 soundsSet.add( sampleId );
    11.             }
    12.         } );
    13.     }
    14.  
    I would post a version of that plugin that exposes more stuff, like volume etc. but i cannot get the javacompiler running, after all, Unity + monodevelop is the only environment i ever really used so far outside of school and i don't want to setup eclipse just for that. Additionally debugging plugins is a time consuming nightmare

    However, didn't @fadden already provide a complete plugin exposing all soundpool parameters?
    http://forum.unity3d.com/threads/android-sound-latency-fix.319943/#post-2091378
     
  25. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    68
    Thanks for your help! I was able to compile your modifications (with some fixs) and created an updated package. I've attached it to the post.

    I didn't test the volume option yet, so if someone could test for me. But the normal version is at least working with both pc and android.

    Edit: Have tested it now, only the volume call. It's working nicely ^^
    I also updated a new package containing the new functions, so download it again.

    To use it now, please attach the script to a gameobject and use AudioCenter.instance

    Credits: Catsknead, Martt, Saishy

    .JAVA
    Code (Java):
    1. package com.catsknead.androidsoundfix;
    2.  
    3. import android.app.Activity;
    4. import android.content.res.AssetFileDescriptor;
    5. import android.media.AudioManager;
    6. import android.media.SoundPool;
    7. import android.util.Log;
    8.  
    9. import java.io.IOException;
    10. import java.util.HashSet;
    11. import java.util.Set;
    12.  
    13. public class AudioCenter extends SoundPool
    14. {
    15.     private final Activity activity;
    16.     private Set<Integer> soundsSet = new HashSet<Integer>();
    17.  
    18.     public AudioCenter( int maxStreams, Activity activity )
    19.     {
    20.         super( maxStreams, AudioManager.STREAM_MUSIC, 0 );
    21.         this.activity = activity;
    22.  
    23.         setOnLoadCompleteListener( new OnLoadCompleteListener() {
    24.             @Override
    25.             public void onLoadComplete( SoundPool soundPool, int sampleId, int status ) {
    26.                 soundsSet.add( sampleId );
    27.             }
    28.         } );
    29.     }
    30.  
    31.     public void play( int soundID )
    32.     {
    33.         if( soundsSet.contains( soundID ) ) {
    34.             play( soundID, 1, 1, 1, 0, 1f );
    35.         }
    36.     }
    37.  
    38.     public void playSound( int soundId )
    39.     {
    40.         if( ( !soundsSet.contains( soundId ) ) || ( soundId == 0 ) ) {
    41.             Log.e( "SoundPluginUnity", "File has not been loaded!" );
    42.             return;
    43.         }
    44.  
    45.         final int sKey = soundId;
    46.  
    47.         activity.runOnUiThread( new Runnable() {
    48.             public void run() {
    49.                 play( sKey );
    50.             }
    51.         } );
    52.     }
    53.  
    54.     public void playSound( int soundId, float volume ) {
    55.         if( ( !soundsSet.contains( soundId ) ) || ( soundId == 0 ) ) {
    56.             Log.e( "SoundPluginUnity", "File has not been loaded!" );
    57.             return;
    58.         }
    59.  
    60.         final int sKey = soundId;
    61.         final float sVolume = volume;
    62.  
    63.         activity.runOnUiThread( new Runnable() {
    64.             public void run() {
    65.                  play( sKey, sVolume, sVolume, 1, 0, 1f );
    66.             }
    67.         } );
    68.     }
    69.  
    70.     public void playSound( int soundId, float leftVolume, float rightVolume, int priority, int loop, float rate ) {
    71.        if( ( !soundsSet.contains( soundId ) ) || ( soundId == 0 ) ) {
    72.             Log.e( "SoundPluginUnity", "File has not been loaded!" );
    73.             return;
    74.         }
    75.  
    76.         final int sKey = soundId;
    77.         final float lVolume = leftVolume;
    78.         final float rVolume = rightVolume;
    79.         final int sPriority = priority;
    80.         final int sLoop = loop;
    81.         final float sRate = rate;
    82.  
    83.         activity.runOnUiThread( new Runnable() {
    84.             public void run() {
    85.                  play( sKey, lVolume, rVolume, sPriority, sLoop, sRate );
    86.             }
    87.         } );
    88.     }
    89.  
    90.     public int loadSound( String soundName )
    91.     {
    92.         AssetFileDescriptor afd;
    93.  
    94.         try {
    95.             afd = activity.getAssets().openFd( soundName );
    96.         } catch( IOException e ) {
    97.             Log.e( "SoundPluginUnity", "File does not exist!" );
    98.             return -1;
    99.         }
    100.  
    101.         int soundId = load( afd, 1 );
    102.  
    103.         soundsSet.add( soundId );
    104.  
    105.         return soundId;
    106.     }
    107.  
    108.     public void unloadSound( int soundId )
    109.     {
    110.         if( unload( soundId ) ) {
    111.             soundsSet.remove( soundId );
    112.         } else {
    113.             Log.e( "SoundPluginUnity", "File has not been loaded!" );
    114.         }
    115.     }
    116. }
    117.  
     

    Attached Files:

    Last edited: Jul 24, 2015
    Marrt likes this.
  26. theuncas

    theuncas

    Joined:
    Feb 21, 2015
    Posts:
    21
    Hello Saishy,

    Thanks you for sharing, i really appreciate it and i'm glad you found a way to resolve your issue.
    Maybe can you answer, but i'm facing a problem with this plugin. I found the sound very choppy, poor quality. Did you noticed it ? or maybe i'm wrong, but i'm not alone to think this..

    Last question, with what tool did you compiled your java class ?

    Thx you
     
  27. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    68
    Really? I didn't notice that, sorry. Maybe someone else can help you :2

    I compiled with Netbeans and Nbadroid, but I think eclipse works as well.
    (I tried using only java and android-sdk but even after I could compile it correctly it was giving me errors when playing)
     
  28. Romaingh

    Romaingh

    Joined:
    Sep 22, 2015
    Posts:
    3
    Hi there,
    it's been a time i'm wondering if there's something wrong with android sound latency, and now i find what seems a great fix !
    BUT the link is dead :( Catsknead, could you please telle me where i can find your fix ? It would be a great help for me, because i'm developping an android game where sound and rythm is important.
    And somenone know if the sound is equally laggy on ios ?
    Thanks :)

    EDIT : my bad, i didn't see you repost your link in the #25 post, thanks a lot, i'm going to try and hope my SFX will be faster =)
     
    Last edited: Sep 23, 2015
  29. theuncas

    theuncas

    Joined:
    Feb 21, 2015
    Posts:
    21
    Hello,

    It's not the original file, but it works as well :)
    If you want the original, i think i can pick it out from my archives ;)
     
  30. WarbyWasTaken

    WarbyWasTaken

    Joined:
    Sep 30, 2015
    Posts:
    1
    Hey,

    My game now plays sounds in the Unity Editor but not on Android. Any ideas?

    EDIT: Never mind, I forgot to put my sounds inside the StreamingAssets folder
     
    Last edited: Sep 30, 2015
  31. phatpixels

    phatpixels

    Joined:
    Sep 18, 2013
    Posts:
    9
    Hello all,

    I saw these postings for Catsknead's android latency fix, but im having trouble hooking it up without a sample scene. Is there any chance of grabbing the example scene to breakdown how it works. Iam somewhat new to unity and trying simply to have a car horn sound play on a ui button press :)
     
  32. fadden

    fadden

    Joined:
    Feb 11, 2015
    Posts:
    13
    Something odd is going on. With Unity 5.1.3, the Unity Editor will not allow WAV files in the Assets/StreamingAssets folder to be treated as AudioClips. I don't see any change in the WAV file metadata. The configuration is still there, but for some reason the editor treats them as opaque data.

    This means that the files are available to Android SoundPool, but you can't drag them onto an AudioSource, because it doesn't recognize the WAV file as an AudioClip.

    You can kluge around the issue by renaming "StreamingAssets", re-importing the WAV files, and then changing the directory name back. This survives editor restarts. However, if you attempt to apply a change to the audio clip import (force mono, change compression type), the WAV file will lose it's AudioClip features and be dropped from the AudioSource.

    I have not tried 5.2.x due to the current state of that code. (I tried it, briefly, then rolled back to 5.1.3.)
     
  33. theuncas

    theuncas

    Joined:
    Feb 21, 2015
    Posts:
    21
    Hey, i have the same issue... It's very weird. But i think that Unity don't parse these objects because it's a special folder used to deploy files on the device after installing.

    Hope it will be fixed very soon because, for now, i have to duplicate my 2 files on another asset directory !

    David
     
  34. fadden

    fadden

    Joined:
    Feb 11, 2015
    Posts:
    13
    It's not immediately clear whether they have introduced a bug or fixed one with this change in behavior. I filed a bug.

    FWIW, I played with it some more and determined that you can work around the change by importing the WAV files into the Assets folder and then simply dragging them into the StreamingAssets folder. Their AudioClip status is lost if the Library folder is removed and rebuilt, though, so it'll be broken for anybody pulling new files out of source control.
     
  35. leolicos

    leolicos

    Joined:
    Dec 1, 2010
    Posts:
    25
    Hello everyone! Great solution! I only have 1 other question: is there any way to store a handle to the current audio being played so I can (for example) change the volume or loop flag of a sound that is currently being played? In my game, I have a sound mixer that allows me to cross fade and mix sounds as they're playing.

    How would I go about adding that functionality into this interface?

    Thanks!
    Leo
     
  36. noambe

    noambe

    Joined:
    Aug 13, 2014
    Posts:
    18
    I'm trying to use this package (taken from #25) on Unity 5.1.1 but I'm a bit confused of where should I place the wav files.
    This line keeps returning null:
    var audioClip = Resources.Load<AudioClip>("Sounds/" + soundName);

    I've put the same wav here:
    Assets\Resources\Sounds\FallSound.wav
    Assets\StreamingAssets\Resources\Sounds\FallSound.wav

    and I tried loading the wav in a couple of ways, all failed:
    AudioCenter.loadSound ("Resources/Sounds/FallSound.wav");
    AudioCenter.loadSound ("FallSound.wav");

    Please clarify because I could really use this plugin.

    UPDATE- I managed to make this work:

    1. wav files should be both under Assets\Resources\Sounds\ and Assets\StreamingAssets\Resources\Sounds\
    2. You need to attach the script to one of your game object so it gets initialized.
    3. You need to invoke AudioCenter.loadSound ("FallSound") // Without the *.wav suffix

    Thanks for this plugin!!!
    Noam
     
    Last edited: Jan 7, 2016
    rameshpy and mandal like this.
  37. Mariolismo

    Mariolismo

    Joined:
    Jul 13, 2015
    Posts:
    4
  38. GaussJordan

    GaussJordan

    Joined:
    Sep 9, 2013
    Posts:
    6
    Hi! I'd very much like access to this plugin aswell, hear our pleads! :)
     
  39. zia badar

    zia badar

    Joined:
    Apr 3, 2016
    Posts:
    1
    Link is down, here is the edited plugin from @Saishy
     

    Attached Files:

    Last edited: Apr 3, 2016
  40. VavylonaEntertainment

    VavylonaEntertainment

    Joined:
    Oct 21, 2015
    Posts:
    142
    Not working. Doesnt play at all
     
  41. Phiru

    Phiru

    Joined:
    Oct 29, 2012
    Posts:
    32
    Thanks in advance.
    And I got an error saying "File does not exist!".
    When I call "loadSound" function with "Resources/Sounds/Bttuon.wav" as a parameter,
    the error's shown.
    I double-checked the path. Did i do something wrong??

    * Solved & Question
    I put the Btton.wav file into "Assets/Resources/Sounds/" Folder. not work.
    But to "Assets/StreamingAssets/Resources/Sounds/" works.

    Activity.getAssets() refers "Assets/StreamingAssets" folder?
     
    Last edited: Jun 15, 2016
  42. Zach28

    Zach28

    Joined:
    Nov 7, 2015
    Posts:
    7
    HEEEEEELP :(
    I have done everything, override for android, not overrided for android, change max streams, everything. But only plays 2 sound effects, back button and enter button, but ball bounce doesn't play, i figured that my buttons sounds has positive number of ID, and bounce sound has a negative number ID, is it because of that? Please help :(
    All sounds are inside SteamingAssets/Resources/Sounds
    Please help :(
    Int ID = 0.

    Update: It's not the ID's fault. Why is it not playing? Someone solved this? Please heeeelp :( been trying to fix this audio delay for days
     
    Last edited: Jun 19, 2016
  43. Zach28

    Zach28

    Joined:
    Nov 7, 2015
    Posts:
    7
    @Saishy Please help :(
    In unity editor, the sound ID is a negative int, but on android build, it's returning 0, i think it's the problem why my audio isn't playing :( please please help :( been trying to fix this for days :(
    I knew that it's returning 0 on android by making a text UI on a canvas and print its value :(
     
    Last edited: Jun 19, 2016
  44. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    520
    Relax. Post your code. No one can help you otherwise.
     
  45. Zach28

    Zach28

    Joined:
    Nov 7, 2015
    Posts:
    7
    I have a Settings script, and a dribble script called by an animation
    Code (CSharp):
    1. public class SettingsManager : MonoBehaviour {
    2.  
    3.     public static SettingsManager settingsManagerScript;
    4.  
    5.     public int button1;
    6.     public int button2;
    7.     public int dribble;
    8.  
    9. void Awake()
    10.     {
    11.         // Get this script instance for other code.
    12.         settingsManagerScript = GetComponent<SettingsManager> ();
    13.     }
    14.  
    15. void Start()
    16.     {
    17. // Load sounds. Dribble sound is named "1".
    18.         button1 = AudioCenter.loadSound("Button1");
    19.         button2 = AudioCenter.loadSound ("Button2");
    20.         dribble = AudioCenter.loadSound("1");
    21.  
    22. etc.
    23.  
    24.  

    And this is the script called by the animation.

    Code (CSharp):
    1. public class PlayDribbleAudio : MonoBehaviour {
    2.  
    3.     SettingsManager settingsScript;
    4.  
    5.     void Start()
    6.     {
    7. // Get the settings script instance
    8.         settingsScript = SettingsManager.settingsManagerScript;
    9.     }
    10.  
    11.     public void playBallAudio()
    12.     {
    13. // Function called by animation
    14.             AudioCenter.playSound(settingsScript.dribble, settingsScript._soundVolume);
    15.     }
    16. }
    thank you in advance :D

    Update: when I click the dribble sound. It shows
    "Vorbis, 44100 Hz, Stereo, 00:00.449 ( this dribble sound's ID returns 0.) So not playing

    and the buttons show:
    "PCM, 44100 Hz, Mono, 00:00.131" (this plays)

    All sound not overrided for android

    Do yyou think it's because of the format?
     
    Last edited: Jun 19, 2016
  46. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    520
  47. Zach28

    Zach28

    Joined:
    Nov 7, 2015
    Posts:
    7
  48. Zach28

    Zach28

    Joined:
    Nov 7, 2015
    Posts:
    7
    @Marrt I tried every free converting software I saw on google. Tried to convert it to a "PCM wav" but it's converting the audio into "Vorbis wav" do you know any converting software? Thank you in advance! :D
     
  49. Zach28

    Zach28

    Joined:
    Nov 7, 2015
    Posts:
    7
    @Marrt , @Saishy
    What audio format do you use? Seems like wav vorbis doesn't work. But unity forces PCM to be converted into vorbis.
    PCM works btw.

    Update: AT LAST! made it to work! :D Thank you very much for this plugin, and thank you @Marrt for replying! :D I dunno how, I think it's just the "PCM" thingy, I did "override for android" with "PCM" compression. Lol
     
    Last edited: Jun 20, 2016
  50. Zach28

    Zach28

    Joined:
    Nov 7, 2015
    Posts:
    7
    @Marrt One last question, do I need to unload it every scene / every application quit? Or when I load another scene, it unloads automatically?

    Update: It unloads automatically.
     
    Last edited: Jun 20, 2016