无法在Android启动画面上播放声音(android studio)

时间:2016-03-21 06:16:00

标签: java android android-studio mobile

当我的启动画面显示在我的Android应用程序上时,我正在尝试播放声音文件....我一直试图弄清楚它几个小时.....当我运行我的应用程序时它现在只是一起跳过了闪屏:

这是我的SplashScreen.java

package com.skapaidbeats.app.skapaidbeats;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import com.skapaidbeats.app.skapaidbeats.MainActivity;
import com.skapaidbeats.app.skapaidbeats.R;
public class SplashScreen extends Activity {

MediaPlayer music;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    Thread timerThread = new Thread(){
        public void run(){
            try{
                music= MediaPlayer.create(SplashScreen.this, R.raw.sound);
                music.start();
                sleep(3000);
            }catch(InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent intent = new Intent(SplashScreen.this,MainActivity.class);
                startActivity(intent);
            }
        }
    };
    timerThread.start();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    music.release();
    finish();
} 
}

这是我的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
package="com.skapaidbeats.app.skapaidbeats">



<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />



<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">


    <activity
        android:name=".SplashScreen"
        android:screenOrientation="portrait"
        android:label="@string/icon_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar">
    </activity>

    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <activity
        android:name="com.startapp.android.publish.list3d.List3DActivity"
        android:theme="@android:style/Theme" />
    <activity
        android:name="com.startapp.android.publish.AppWallActivity"
        android:configChanges="orientation|keyboardHidden"
        android:theme="@android:style/Theme.Translucent" />
    <activity
        android:name="com.startapp.android.publish.OverlayActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:theme="@android:style/Theme.Translucent" />
    <activity
        android:name="com.startapp.android.publish.FullScreenActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:theme="@android:style/Theme" />


</application>
</manifest>

2 个答案:

答案 0 :(得分:0)

您是否在清单中声明了您的活动?

如果您这样做,之前会问过这个问题,请尝试以下方法:

Android Sound not playing in splash screen

How to play audio in splash screen in android

答案 1 :(得分:0)

你可以试试这个

MediaPlayer player = new MediaPlayer();
player.setDataSource("/sdcard/audiotrack.mp3");
player.prepare();
player.start();