Announcement

Collapse
No announcement yet.

Using Sounds in Java

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

  • #16
    Originally posted by alan_16072 View Post
    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.

    I don't use Android Studio
    is there any way to do it in the onbot java

    Comment


    • #17
      Oh, well that makes sense why the other directions weren't working for you. I haven't tried this with OnBot Java, but here is the sample file for it:
      https://github.com/ftctechnh/ftc_app...OnBotJava.java

      Comment


      • #18
        Your build problems appear to be the redirect to the robot hardware class. Line 15 error is calling a hardware class called robot. Line 10 sets the variable robot to robot. These are further defined in the OpMode that was extended.

        Comment


        • #19
          Originally posted by alan_16072 View Post
          Oh, well that makes sense why the other directions weren't working for you. I haven't tried this with OnBot Java, but here is the sample file for it:
          https://github.com/ftctechnh/ftc_app...OnBotJava.java
          Here are the errors that that sample gives me.


          line 102, column 58: ERROR: cannot find symbol symbol: method startPlaying(android.content.Context,java.io.File)
          location: class com.qualcomm.ftccommon.SoundPlayer
          line 109, column 58: ERROR: cannot find symbol symbol: method startPlaying(android.content.Context,java.io.File)
          location: class com.qualcomm.ftccommon.SoundPlayer

          Comment


          • #20
            I just did it in OnBot Java and it worked for me. Do you have version 4.3 of the Robot Controller installed on your phone?

            Comment


            • #21
              Originally posted by alan_16072 View Post
              I just did it in OnBot Java and it worked for me. Do you have version 4.3 of the Robot Controller installed on your phone?
              Yeah i have version app version 4.3
              I have library version 18.10.31

              Comment


              • #22
                Here is the code I used
                Code:
                /* Copyright (c) 2018 FIRST. All rights reserved.
                 *
                 * Redistribution and use in source and binary forms, with or without modification,
                 * are permitted (subject to the limitations in the disclaimer below) provided that
                 * the following conditions are met:
                 *
                 * Redistributions of source code must retain the above copyright notice, this list
                 * of conditions and the following disclaimer.
                 *
                 * Redistributions in binary form must reproduce the above copyright notice, this
                 * list of conditions and the following disclaimer in the documentation and/or
                 * other materials provided with the distribution.
                 *
                 * Neither the name of FIRST nor the names of its contributors may be used to endorse or
                 * promote products derived from this software without specific prior written permission.
                 *
                 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
                 * LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
                 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
                 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
                 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
                 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
                 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
                 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
                 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                 */
                
                package org.firstinspires.ftc.teamcode;
                
                import com.qualcomm.ftccommon.SoundPlayer;
                import com.qualcomm.robotcore.eventloop.opmode.Disabled;
                import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
                import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
                import java.io.File;
                
                /**
                 * This file demonstrates how to play simple sounds on both the RC and DS phones.
                 * It illustrates how to play sound files that have been copied to the RC Phone
                 * This technique is best suited for use with OnBotJava since it does not require the app to be modified.
                 *
                 * Operation:
                 *
                 * Gamepad X & B buttons are used to trigger sounds in this example, but any event can be used.
                 * Note: Time should be allowed for sounds to complete before playing other sounds.
                 *
                 *  To play a new sound, you will need to copy the .wav files to the phone, and then provide the full path to them as part of your OpMode.
                 *  This is done in this sample for the two sound files.  silver.wav and gold.wav
                 *
                 *  You can put the files in a variety of soundPaths, but we recommend you put them in the /FIRST/blocks/sounds folder.
                 *  Your OpModes will have guaranteed access to this folder, and you can transfer files into this folder using the BLOCKS web page.
                 *  --  There is a link called "sounds" on the right hand side of the color bar on the BLOCKS page that can be used to send sound files to this folder by default.
                 *  Or you can use Windows File Manager, or ADB to transfer the sound files
                 *
                 *  To get full use of THIS sample, you will need to copy two sound file called silver.wav and gold.wav to /FIRST/blocks/sounds on the RC phone.
                 *  They can be located here:
                 *      https://github.com/ftctechnh/ftc_app/tree/master/FtcRobotController/src/main/res/raw/gold.wav
                 *      https://github.com/ftctechnh/ftc_app/tree/master/FtcRobotController/src/main/res/raw/silver.wav
                 */
                
                @TeleOp(name="Concept: Sound Files", group="Concept")
                @Disabled
                public class OnBotSoundSample extends LinearOpMode {
                
                    // Point to sound files on the phone's drive
                    private String soundPath = "/FIRST/blocks/sounds";
                    private File goldFile   = new File("/sdcard" +  soundPath + "/gold.wav");
                    private File silverFile = new File("/sdcard" + soundPath + "/silver.wav");
                
                    // Declare OpMode members.
                    private boolean isX = false;    // Gamepad button state variables
                    private boolean isB = false;
                
                    private boolean wasX = false;   // Gamepad button history variables
                    private boolean WasB = false;
                
                    @Override
                    public void runOpMode() {
                
                        // Make sure that the sound files exist on the phone
                        boolean goldFound   = goldFile.exists();
                        boolean silverFound = silverFile.exists();
                
                        // Display sound status
                        telemetry.addData("gold sound",   goldFound ?   "Found" : "NOT Found \nCopy gold.wav to " + soundPath  );
                        telemetry.addData("silver sound", silverFound ? "Found" : "NOT Found \nCopy silver.wav to " + soundPath );
                
                        // Wait for the game to start (driver presses PLAY)
                        telemetry.addData(">", "Press Start to continue");
                        telemetry.update();
                        waitForStart();
                
                        telemetry.addData(">", "Press X or B to play sounds.");
                        telemetry.update();
                
                        // run until the end of the match (driver presses STOP)
                        while (opModeIsActive()) {
                
                            // say Silver each time gamepad X is pressed (This sound is a resource)
                            if (silverFound && (isX = gamepad1.x) && !wasX) {
                                SoundPlayer.getInstance().startPlaying(hardwareMap.appContext, silverFile);
                                telemetry.addData("Playing", "Silver File");
                                telemetry.update();
                            }
                
                            // say Gold each time gamepad B is pressed  (This sound is a resource)
                            if (goldFound && (isB = gamepad1.b) && !WasB) {
                                SoundPlayer.getInstance().startPlaying(hardwareMap.appContext, goldFile);
                                telemetry.addData("Playing", "Gold File");
                                telemetry.update();
                            }
                
                            // Save last button states
                            wasX = isX;
                            WasB = isB;
                        }
                    }
                }
                the red text is the part giving me trouble

                Comment


                • #23
                  using OnBotJava, I told it to use the sample from the drop down list. I'll check and make sure it was the same, but I think it Is.

                  I'll check the library version when I get home. Do you have "adb" set up with the phone? If so, see if you can push this file to the phone: https://github.com/ftctechnh/ftc_app...er-release.apk

                  If not, let me know and I'll erase RobotController from a phone and go pull it from the "Google Play Store"

                  Comment


                  • #24
                    Originally posted by alan_16072 View Post
                    using OnBotJava, I told it to use the sample from the drop down list. I'll check and make sure it was the same, but I think it Is.

                    I'll check the library version when I get home. Do you have "adb" set up with the phone? If so, see if you can push this file to the phone: https://github.com/ftctechnh/ftc_app...er-release.apk

                    If not, let me know and I'll erase RobotController from a phone and go pull it from the "Google Play Store"
                    No I don't have "abd" on the phone.
                    I'll try redownloading the robot controller as well

                    Comment


                    • #25
                      Originally posted by miner90027 View Post

                      No I don't have "abd" on the phone.
                      I'll try redownloading the robot controller as well
                      I just reinstalled the rc & it still fails to build
                      the app & library version stayed the same

                      Comment


                      • #26
                        I wiped the robot controller from the phone and uploaded the file you had above and it worked great. No problem whatsoever. So I am afraid I don't know what else to try.

                        Sorry,

                        Alan

                        Comment


                        • #27
                          Originally posted by alan_16072 View Post
                          I wiped the robot controller from the phone and uploaded the file you had above and it worked great. No problem whatsoever. So I am afraid I don't know what else to try.

                          Sorry,

                          Alan
                          What is the library version on your phones
                          ​​​​​​

                          Comment


                          • #28
                            Originally posted by alan_16072 View Post
                            I wiped the robot controller from the phone and uploaded the file you had above and it worked great. No problem whatsoever. So I am afraid I don't know what else to try.

                            Sorry,

                            Alan
                            Well at least I know it Isn't aproblem with the code.

                            Comment


                            • #29
                              Originally posted by alan_16072 View Post
                              I wiped the robot controller from the phone and uploaded the file you had above and it worked great. No problem whatsoever. So I am afraid I don't know what else to try.

                              Sorry,

                              Alan
                              I FIXED IT!

                              All I had to do was reset my onBot java entirely

                              Comment


                              • #30
                                It turns out that my OnBot java itself was broken & needed to be reset.

                                Comment

                                Working...
                                X