Archive for the ‘Sound’ Category
Ein Android Splash Screen Tutorial (mit mp3 Sound)
Ein Android Splash Screen Tutorial (mit mp3 Sound)
Es ist immer gut, wenn eine Android App uns mit einen Splash Screen begrüßt. Hier ein Tutorial dafür:
Der splash.xml:
<?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/back" > </LinearLayout>

Der Manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.worldling" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <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=".Sound1" android:label="@string/app_name" > <intent-filter> <action android:name="de.worldling.SOUND1" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> </manifest>
Und die Java Classe, splash.java:
package de.worldling;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
mp = MediaPlayer.create(Splash.this, R.raw.sound1);
mp.start();
Thread timer = new Thread() {
public void run() {
try {
sleep(5000);// 5 seconds
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent openStartingPoint = new Intent("de.worldling.SOUND1");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mp.release();
finish();
}
}
Android Tutorial – Mp3 Sounds mit Button abspielen
Android Tutorial - Mp3 Sounds mit Button abspielen
Eine einfache App, mit der man einen Mp3 Sound abspielen kann.

main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/bAudio" android:layout_width="250dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="50dp" android:text="Audio 1" android:textSize="20dp" /> <Button android:id="@+id/bAudio2" android:layout_width="250dp" android:layout_height="wrap_content" android:layout_gravity="center" android:text="Audio 2" android:textSize="20dp" /> </LinearLayout>
Unsere Activity
package de.worldling;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Sound1 extends Activity {
public MediaPlayer mp;
Button audio1, audio2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
audio1 = (Button) findViewById(R.id.bAudio);
audio2 = (Button) findViewById(R.id.bAudio2);
audio1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mp = MediaPlayer.create(getApplicationContext(), R.raw.sound1);
mp.start();
}
});
audio2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mp = MediaPlayer.create(getApplicationContext(), R.raw.sound2);
mp.start();
}
});
}
}

