Java 我想在启动屏幕中嵌入声音。当活动发生变化时,它必须停止

Java 我想在启动屏幕中嵌入声音。当活动发生变化时,它必须停止,java,android,xml,Java,Android,Xml,SplashScreen.java- package com.example.android.nxtgendataingestion; import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import gr.net.maroulis.library.EasySplashScreen;

SplashScreen.java-

package com.example.android.nxtgendataingestion;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import gr.net.maroulis.library.EasySplashScreen;

public class SplashScreen extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EasySplashScreen config=new EasySplashScreen(SplashScreen.this)
                .withFullScreen()
                .withTargetActivity(MainActivity.class)
                .withSplashTimeOut(3000)
                .withBackgroundColor(Color.parseColor("#ebedef"))
                .withLogo(R.drawable.nxtgenlogo)
                .withAfterLogoText("NxtGen Grafana Dashboard");


        //Set Text Color

        View view=config.create();
        setContentView(view);


    }
}

我正在处理一个项目,我想将.ogg扩展名声音剪辑用于此活动,当更改为其他活动时,它必须停止。

在应用程序中创建原始文件夹:在原始文件夹中放置声音文件(此处为悬挂铃声) `试试这个:

     EasySplashScreen config=new EasySplashScreen(SplashScreen.this)
                    .withFullScreen()
                    .withTargetActivity(MainActivity.class)
                    .withSplashTimeOut(3000)
                    .withBackgroundColor(Color.parseColor("#ebedef"))
                    .withLogo(R.drawable.nxtgenlogo)
                    .withAfterLogoText("NxtGen Grafana Dashboard");


            //Set Text Color

            View view=config.create();
            setContentView(view);
    final MediaPlayer player = new MediaPlayer();
AssetFileDescriptor afd = this.getResources().openRawResourceFd(R.raw.hangout_ringtone);
player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
player.setAudioStreamType(AudioManager.STREAM_ALARM);
player.setLooping(true);
player.prepare();
    player.start();
                // wait 3 sec... then stop the player.
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        player.stop();
                    }
                }, 3000);
    `

选中此项,这可能会对您有所帮助。请将代码包装在函数中,以便您可以查看缩进是如何工作的。我还怀疑你的缩进有问题?