2017-06-15 38 views
0

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擴展聲音剪輯這項活動的工作被停止,它必須停止時改投其他活動。

+0

檢查這個https://stackoverflow.com/questions/3370211/how-to-play -audio-in-splash-screen-in-android和http://www.coderefer.com/android-splash-screen-example-tutorial/ 這可能會幫助你。 –

回答

0

使原始文件夾中的應用程序:把聲音文件(這裏hangout_ringtone)在原文件夾 `試試這個:

 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); 
    ` 
+0

請將代碼封裝在函數中,以便查看縮進如何工作。我還懷疑你的縮進是關閉的? – dhdavvie