No sound from apk debug built package

Asked 2 years ago, Updated 2 years ago, 113 views

Thank you for your help.

I am creating an Android app with monaca.
The actual debugger played sound, but when you create and run a debug build of the package, the apk package does not play sound.Other apps make sound, so it's not a malfunction of the main unit.

As for Android app settings, I changed the WebView engine to high performance and built it, but it still doesn't produce sound.
I was wondering, so I just used the script that was introduced in support, but it also doesn't sound.

The script is listed below, but is there anything that can be improved?

Also, the terminal I tested is
Sony Xperia tablet S1 (Android 4.1.1)
asus Nexus 7 (Android 5.1.1)
That's it.

Thank you for your cooperation.

<script>
    ons.bootstrap();

            document.addEventListener("deviceready", onDeviceReady, false);

    // Android specifies the absolute path to read the mp3 file in the project.It's a function for that.
    function getPath(){
        var str = location.pathname;
        vari=str.lastIndexOf('/');
        return str.substring(0,i+1);
    }

    function onDeviceReady() {
        window.alert("PhoneGap Load Completed.");
    }

    varmedia = null;
    varmediaTimer = null;

    // This is a function to play.
    functionplayAudio(){


        var src = 'beep1.mp3';


        media=newMedia(getPath()+src, onSuccess, onError);

        // Play it.Loop playback is possible by adding {numberOfLoops: "infinite"}.
        media.play({numberOfLoops:"infinite"});

        if(mediaTimer==null){

            mediaTimer=setInterval(function(){

                // Returns the playback position
                media.getCurrentPosition(

                    // Callback function on success
                    function(position){
                        if(position>-1){
                            setAudioPosition((position)+"sec");

                                    // Some terminals stop playing at -0.001, so read again.
                                    if(position==-0.001){

                                        media.play({numberOfLoops:"infinite"});

                                    }
                        }
                    },
                    // Callback function on failure
                    function(e){

                        console.log("Error getting pos="+e);
                        setAudioPosition("Error:"+e);

                    }
                );
            }, 1000);
        }
    }

    // Function that pauses playback
    function pauseAudio(){

        if(media){
            media.pause();
        }
    }

    // Function to stop playback
    function stopAudio(){

        if(media){
            media.stop();
        }

        clearInterval (mediaTimer);
        mediaTimer=null;
    }

      // Callback function on success.This is a message that the debug log was successful.
      function onSuccess() {
          console.log("playAudio():Audio Success";
      }

      // Callback function on failure
      function onError(error){
          alert('code:'+error.code+'\n'+ 
                'message:'+error.message+'\n');
      }

      // Audio playback location
      function setAudioPosition(position){
          document.getElementById('audio_position').innerHTML=position;
      }

    </script>

android monaca

2022-09-30 18:17

1 Answers

Select FileManage Codova Plug-in from the Monaca Cloud IDE to enable and rebuild the Media plug-in.
MediaChecked with enabled/disabled plug-in and MP3 played.

Other features work well with Monaca debuggers, but if they don't work when built, enabling the Cordova plug-in seems to solve the problem.


2022-09-30 18:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.