Announcement

Collapse
No announcement yet.

Using Sounds in Java

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

  • miner90027
    replied
    Originally posted by 3805Mentor View Post
    How did you reset OnBotJava? This thread got me interested in playing with this. I started as recommended with the Onbot version where I get the same error as shown earlier in the thread. I then tried downloading the AS version from AS and putting the wav files where advised, and that version worked fine.

    I'm not sure what you mean by resetting OnBotJava?
    In the top left corner you have the settings icon, click it. Scroll all the way to the bottom, there should be a red box surrounding 3 buttons. There is one that erases everything in OnBot java and resets it. that is the button you press, but only after backing up all of your programs in java.

    Leave a comment:


  • 3805Mentor
    replied
    How did you reset OnBotJava? This thread got me interested in playing with this. I started as recommended with the Onbot version where I get the same error as shown earlier in the thread. I then tried downloading the AS version from AS and putting the wav files where advised, and that version worked fine.

    I'm not sure what you mean by resetting OnBotJava?

    Leave a comment:


  • alan_16072
    replied
    Originally posted by miner90027 View Post

    I FIXED IT!

    All I had to do was reset my onBot java entirely
    That is terrific! Thanks for sharing here so that another team searching will get the idea to reset the OnBot Java!!

    --Alan

    Leave a comment:


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

    Leave a comment:


  • miner90027
    replied
    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

    Leave a comment:


  • miner90027
    replied
    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.

    Leave a comment:


  • miner90027
    replied
    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
    ​​​​​​

    Leave a comment:


  • alan_16072
    replied
    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

    Leave a comment:


  • miner90027
    replied
    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

    Leave a comment:


  • miner90027
    replied
    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

    Leave a comment:


  • alan_16072
    replied
    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"

    Leave a comment:


  • miner90027
    replied
    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

    Leave a comment:


  • miner90027
    replied
    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

    Leave a comment:


  • alan_16072
    replied
    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?

    Leave a comment:


  • miner90027
    replied
    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

    Leave a comment:

Working...
X