Announcement

Collapse
No announcement yet.

Using Sounds in Java

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Sounds in Java

    I am having trouble using sounds in Java. I have goten it to work in Blocks, however my team is in the process of converting to Java.
    I have tried the samples and they don't compile, and it gives me a huge list of errors.
    I have tried creating a dummy program in blocks then converting it to java, but that doesn't work either.
    This is dummy code in converted from blocks in Java:
    Code:
    package org.firstinspires.ftc.teamcode;
    import com.qualcomm.ftccommon.SoundPlayer;
    import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
    import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
    import org.firstinspires.ftc.robotcore.external.android.AndroidSoundPool;
    
    @TeleOp(name = "sound (Blocks to Java)", group = "")
    public class sound extends LinearOpMode {
    
      private AndroidSoundPool androidSoundPool;
    
      /**
       * This function is executed when this Op Mode is selected from the Driver Station.
       */
      @Override
      public void runOpMode() {
        androidSoundPool = new AndroidSoundPool();
    
        // Put initialization blocks here.
    androidSoundPool.initialize(SoundPlayer.getInstance()); // this is where all of my problems are occuring
        androidSoundPool.setVolume(1F);
        waitForStart();
        if (opModeIsActive()) {
          // Put run blocks here.
          while (opModeIsActive()) {
            if (gamepad1.a == true) {
              androidSoundPool.play("r2d2Scream.mp3");
            }
            if (gamepad1.b == true) {
              androidSoundPool.play("WiiSports.mp3");
            }
            if (gamepad1.x == true) {
              androidSoundPool.play("nope.mp3");
            }
            // Put loop blocks here.
            telemetry.update();
          }
        }
    
        androidSoundPool.close();
      }
    }
    This is the error it gives: ERROR: incompatible types: com.qualcomm.ftccommon.SoundPlayer cannot be converted to org.firstinspires.ftc.robotcore.internal.android.S oundPoolIntf

  • #2
    We have it working like a champ. We used ConceptSoundsASJava in the external.samples.

    If you look here, you can see the commit one of our team members did so that our robot could quack.

    https://github.com/ftc16072/2019pres...fdbd3fcd692290

    --Alan
    Coach FTC #16072, Quantum Quacks

    Comment


    • #3
      I will try this.
      Is there anything that I would need to do with the robot phones before implimenting the program? Ex: save the sound file in a specific folder or use an external speaker?

      Comment


      • #4
        Originally posted by alan_16072 View Post
        We have it working like a champ. We used ConceptSoundsASJava in the external.samples.

        If you look here, you can see the commit one of our team members did so that our robot could quack.

        https://github.com/ftc16072/2019pres...fdbd3fcd692290

        --Alan
        Coach FTC #16072, Quantum Quacks
        Which opmode is it that makes the robot quack because i tried it and it still didn't build.

        Comment


        • #5
          You need to have a quack.wav stored in TeamCode/res/raw
          The OpMode that makes it quack is QuackOpMode

          Comment


          • #6
            That is on your project, the sound gets built as part of FTCRobotController. You don't need the file on the phone separately.

            Comment


            • #7
              Originally posted by alan_16072 View Post
              That is on your project, the sound gets built as part of FTCRobotController. You don't need the file on the phone separately.
              That is true, although the more bloat that you add to the project, the longer transferring the APK to the phone takes

              Comment


              • #8
                Originally posted by 4634 Programmer View Post

                That is true, although the more bloat that you add to the project, the longer transferring the APK to the phone takes
                Other than breaking out resource files, any other tips for reducing the time? It seems to take a long time to transfer already...

                --Alan

                Comment


                • #9
                  Originally posted by alan_16072 View Post

                  Other than breaking out resource files, any other tips for reducing the time? It seems to take a long time to transfer already...

                  --Alan
                  Last season I has 8-second wireless deploys using OpenRC Turbo. Unfortunately, things happened and it wasn't upgraded to v4.x to be legal for competition this year. However, there are plans to upgrade it to v5.x when alpha SDK 5.1 comes out in the very near future.

                  Comment


                  • #10
                    I tried to copy & paste the QuackOpMode but it still wouldnt build.
                    error.png

                    Comment


                    • #11
                      ERROR: constructor Robot in class com.qualcomm.robotcore.robot.Robot cannot be applied to given types;
                      required: com.qualcomm.robotcore.eventloop.EventLoopManager
                      found: no arguments reason: actual and formal argument lists differ in length org/firstinspires/ftc/teamcode/QuackOpMode.java
                      line 15, column 22: ERROR: cannot find symbol symbol: method init(com.qualcomm.robotcore.hardware.HardwareMap) location: variable robot of type com.qualcomm.robotcore.robot.Robot org/firstinspires/ftc/teamcode/QuackOpMode.java line 16, column 22: ERROR: cannot find symbol symbol: method quack() location: variable robot of type com.qualcomm.robotcore.robot.Robot org/firstinspires/ftc/teamcode/QuackOpMode.java line 23, column 30: ERROR: cannot find symbol symbol: method quack() location: variable robot of type com.qualcomm.robotcore.robot.Robot


                      These are the errors that it gave me.

                      Comment


                      • #12
                        We have a Robot class. (ie, it isn't from com.qualcomm but is from org.firstinspires.ftc ). You can see all of the code (instead of just the differences here: https://github.com/ftc16072/2019pres...s/ftc/teamcode

                        Although, I think you'll have the best luck if you just use the sample code here:
                        https://github.com/ftc16072/2019pres...ndsASJava.java

                        Hope this helps!!

                        --Alan

                        Comment


                        • #13
                          Originally posted by alan_16072 View Post
                          We have a Robot class. (ie, it isn't from com.qualcomm but is from org.firstinspires.ftc ). You can see all of the code (instead of just the differences here: https://github.com/ftc16072/2019pres...s/ftc/teamcode

                          Although, I think you'll have the best luck if you just use the sample code here:
                          https://github.com/ftc16072/2019pres...ndsASJava.java

                          Hope this helps!!

                          --Alan
                          I have tried the sample it just keeps giving me similar errors.

                          Comment


                          • #14
                            If you download the whole archive: https://github.com/ftc16072/2019pres...ive/master.zip , and open it with Android Studio does that build?

                            If not, make sure you have accepted the SDK licenses.


                            Comment


                            • #15
                              Obviously you have to unzip the archive into a directory first and then open that directory with Android Studio.

                              Comment

                              Working...
                              X