Tuesday, March 26, 2013

Android Application Tutorial-Music

MainActivity
****************************************************************
package com.nanolaser;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
   
}
*******************************************************************
Splash
*******************************************************************
package com.nanolaser;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity{
     MediaPlayer ourSong;
 @Override
 protected void onCreate(Bundle TravisLoveBacon) {
  // TODO Auto-generated method stub
  super.onCreate(TravisLoveBacon);
  setContentView(R.layout.splash);
  ourSong=MediaPlayer.create(Splash.this, R.raw.music);
  ourSong.start();
  Thread timer=new Thread(){
   public void run(){
    try{
     sleep(5000);
    
    }catch(InterruptedException e){
     e.printStackTrace();
    }finally{
     Intent openStartingPoint=new Intent("com.nanolaser.MAINACTIVITY");
     startActivity(openStartingPoint);
    
    }
   
   }
  };
  timer.start();
 }
 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  ourSong.release();
  finish();
 }
   
}
***************************************************************
activity_main
****************************************************************
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
</RelativeLayout>

*******************************************************************
splash
*******************************************************************
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/splash_background"
   
    >
   
</LinearLayout>
*********************************************************************
AndroidManifest.xml
*********************************************************************
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.nanolaser"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Splash"
            android:label="@string/app_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:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.nanolaser.MAINACTIVITY" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>



No comments:

Post a Comment