EasyHits4U.com - Your Free Traffic Exchange - 1:1 Exchange Ratio, 5-Tier Referral Program. FREE Advertising!

Thursday, 27 November 2014

Android Development [Episode -08] :: Add to Android App Mediaplayer

                                                                        


Today we will learn how the Android app to add Mediaplayer. setContentView (R.layout.activity_main); Of the song = MediaPlayer.create (MainActivity.this, R.drawable.sky_wave_sea); thus Declare day. Here is the song globally, Mediaplayer song Declare the day. Activity MainActivity.this here through direct and R.drawable. sky_wave_sea where sky_wave_sea.mp3 T res> drawable folder has been copied. Then song.start (); Declare the day.


 package com.art.android6;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

MediaPlayer song;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 song = MediaPlayer.create(MainActivity.this, R.drawable.sky_wave_sea);

 song.start();

 Thread nthread = new Thread(){

 @Override
 public void run() {

 try {

 sleep(18648);

 }
 catch (InterruptedException e) {

 e.printStackTrace();

 }

 finally {

 Intent nIntent = new Intent("com.art.android6.activity_second");

 startActivity(nIntent);

 } }
 };

 nthread.start();

 }

 @Override
 protected void onPause() {

 song.release();

 super.onPause();
 }
}


Then in the onPause method song.release (); Please release this song. Now when you run the app will start playing as ringtones. Android App today to add to this tutorial Mediaplayer.

Android Development [Episode -01] clicks hear

No comments:

Post a Comment