简体   繁体   中英

Audio sound is not playing in Android

I'm learning android app development. Now, when I tried to upload an audio file named "audio.mp3" in res > raw folder in the android studio the audio sound is not playing. and also when running it on an emulator there is no sound. But I found that the file is completely fine. What should I do now?

my code is:

package com.example.audiocontroller;

import android.media.MediaPlayer;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.audio);
        mediaPlayer.start();



    }
}

here's a screenshot look audio is completely fine

Hi the code is perfect the only issue I think is with the emulator you are trying to run. You can check the above app with the real device and you should be able to hear the your .mp3 file sound as soon as app launches. Other then that you can have a look here which describes the problem with the emulator sound.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM