Twitter Facebook Delicious Digg Stumbleupon Favorites More

Monday, 15 January 2018

arti type app new line solution

<resources>
    <string name="app_name">Del</string>
    <string name="hindi">

        <html> जय देव, जय देव, जय शिव मार्तंडा…\n
हरी मदन मल्हारी तूची प्रचंडा…जय देव !\n
\n
जेजुरगड पर्वत शिवलिंगाकार, मृत्युलोकी दुसरे कैलास शिखर,\n
नाना परि ती रचना रचली अपार,\n
त्रयेस्थळी नांदे स्वामी शंकर....जय देव !\n
जय देव, जय देव, जय शिव मार्तंडा…\n
हरी मदन मल्हारी तूची प्रचंडा…जय देव !\n
\n
मणि-मल्ल दैत्य प्रबळ तो झाला,\n
देव-गण-गंधर्व कापति त्याला,\n
हाती तलवार, खडग, त्रिशूळ, भाला,\n
आदि शक्ती म्हाळसा घेउन संगतिला....जय देव !\n
जय देव, जय देव, जय शिव मार्तंडा…\n
हरी मदन मल्हारी तूची प्रचंडा…जय देव !\n
\n
चंपा शष्ठी दिवशी अवतार धरिशी,\n
मणि-मल्ल दैत्यांचा संहार करीशी,\n
चरणी पृष्टि वरति खडग़ स्थापिशी,\n
अंति वर देउनी त्यास मुक्ति दे देशी.....जय देव !\n
जय देव, जय देव, जय शिव मार्तंडा…\n
हरी मदन मल्हारी तूची प्रचंडा…जय देव !\n
\n
मणि-मल्ल दैत्य मर्दुनी मल्हारी,\n
देवा संकट पडता राहे जेजूरी,\n
अर्धांगी म्हाळसा शोभे सुंदरी,\n
देवा ठाव मागे दास नरहरि....जय देव !\n
जय देव, जय देव, जय शिव मार्तंडा…\n
हरी मदन मल्हारी तूची प्रचंडा…जय देव !\n</html>
    </string>
</resources>


or plz check

TextView txtSubTitle = (TextView)findViewById(r.id.txtSubTitle);
txtSubTitle.setText(Html.fromHtml(getResources().getString(R.string.sample_string)));
Share:

Tuesday, 9 January 2018

xylopone android app


MAIN ACTIVITY

package com.example.viraj.xylopone_music;

import android.media.AudioManager;
import android.media.SoundPool;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.lang.ref.PhantomReference;

public class MainActivity extends AppCompatActivity {
//HELPFUL CONSTANT
    private final int NR_OF_SIMULATANEOUS_SOUND=7;
    private final float LEFT_VOLUME=1.0f;
    private final float RIGHT_VOLUME=1.0f;
    private final int NO_LOOP=0;
    private final int PRIORITY=0;
    private final float NORMAL_PLAY_RATE=1.0f;

    //TODO add MEMBER VARIABLE HERE
    private SoundPool mSoundPool;
    private int nASoundID;
    private int nBSoundID;
    private int nCSoundID;
    private int nDSoundID;
    private int nESoundID;
    private int nFSoundID;
    private int nGSoundID;
    private int nHSoundID;



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

        //todo create a sound
        mSoundPool=new SoundPool(7, AudioManager.STREAM_MUSIC,0);

        //todo load and get the id to identify the sound
        nASoundID=mSoundPool.load(getApplicationContext(),R.raw.note6_a,1);
        nBSoundID=mSoundPool.load(getApplicationContext(),R.raw.note7_b,1);
        nCSoundID=mSoundPool.load(getApplicationContext(),R.raw.note1_c,1);
        nDSoundID=mSoundPool.load(getApplicationContext(),R.raw.note2_d,1);
        nESoundID=mSoundPool.load(getApplicationContext(),R.raw.note3_e,1);
        nFSoundID=mSoundPool.load(getApplicationContext(),R.raw.note4_f,1);
        nGSoundID=mSoundPool.load(getApplicationContext(),R.raw.note5_g,1);
        nHSoundID=mSoundPool.load(getApplicationContext(),R.raw.lst,1);
        //todo add the play method triggered by button

    }
    //todo Add the play method triggered by the button
    public void playC(View v)
    {
       // mSoundPool.play(nASoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);   same hi he demo he niche valal
mSoundPool.play(nCSoundID,1.0f,1.0f,0,0,1.0f);
    }
    public void playD(View v)
    {
        mSoundPool.play(nDSoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
    public void playE(View v)
    {
        mSoundPool.play(nESoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
    public void playF(View v)
    {
        mSoundPool.play(nFSoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
    public void playG(View v)
    {
        mSoundPool.play(nGSoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
    public void playA(View v)
    {
        mSoundPool.play(nASoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
    public void playB(View v)
    {
        mSoundPool.play(nBSoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
    public void playH(View v)
    {
        mSoundPool.play(nHSoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
}

XML FILE

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.viraj.xylopone_music.MainActivity">

    <Button
        style="@style/KeyStyle"
        android:id="@+id/c_key"
        android:background="@color/red"
        android:onClick="playC"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button style="@style/KeyStyle"
        android:background="@color/orange"
        android:id="@+id/d_key"
        android:onClick="playD"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <Button style="@style/KeyStyle"
        android:id="@+id/e_key"
        android:background="@color/yellow"
        android:onClick="playE"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <Button style="@style/KeyStyle"
        android:id="@+id/f_key"
        android:background="@color/green"
        android:onClick="playF"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button style="@style/KeyStyle"
        android:id="@+id/g_key"
        android:background="@color/turquoise"
        android:onClick="playG"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button style="@style/KeyStyle"
        android:id="@+id/a_key"
        android:background="@color/blue"
        android:onClick="playA"
        android:layout_marginLeft="25dp"
        android:layout_marginRight="25dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button style="@style/KeyStyle"
        android:id="@+id/b_key"
        android:background="@color/purple"
        android:onClick="playB"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button style="@style/KeyStyle"
        android:background="@color/red"
        android:id="@+id/h_key"
        android:onClick="playH"
        android:layout_marginLeft="35dp"
        android:layout_marginRight="35dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

</LinearLayout>

COLOUR
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>

    <color name="colorAccent">#FF4081</color>

    <color name="colorPrimaryDark">#000000</color>
    <color name="red">#e74c3c</color>
    <color name="orange">#e67e22</color>
    <color name="yellow">#f1c40f</color>
    <color name="turquoise">#1abc9c</color>
    <color name="green">#2ecc71</color>
    <color name="blue">#3498db</color>
    <color name="purple">#9b59b6</color>

</resources>

STYLE
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="KeyStyle">
        <item name="android:layout_weight">1</item>
        <item name="android:layout_marginTop">3dp</item>
        <item name="android:layout_marginBottom">3dp</item>
    </style>

</resources>




Share:

Monday, 8 January 2018

Android App Magic Ball 8

Android App Magic Ball 8 


package com.example.viraj.magic_8_ball;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {
private Button rollbutton;
private ImageView imageview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rollbutton=(Button)findViewById(R.id.id_button);
        imageview=(ImageView)findViewById(R.id.id_image);
final int [] arrayimage={
        R.drawable.ball1,
        R.drawable.ball2,
        R.drawable.ball3,
        R.drawable.ball4,
        R.drawable.ball5
};
        rollbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Random random=new Random();
                int randomnogene=random.nextInt(arrayimage.length);//or int randomnogene=random.nextInt(5);
                imageview.setImageResource(arrayimage[randomnogene]);
            }
        });
    }
}



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.viraj.magic_8_ball.MainActivity"
    android:background="#4FC3F7">

    <TextView
        android:id="@+id/text_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:text="@string/txttitle"
        android:textAlignment="center"
        android:textColor="#E91E63"
        android:textSize="20sp"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/id_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        app:srcCompat="@drawable/ball1" />

    <Button
        android:id="@+id/id_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/id_image"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="41dp"
        android:shadowColor="#FF5722"
        android:textColor="#E91E63"
        android:textStyle="bold"
        android:text="@string/buttonname" />
</RelativeLayout>




Share:

Saturday, 6 January 2018

Dice App random number based

package com.example.viraj.diceapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.Random;

public class MainActivity extends AppCompatActivity {
    Button rollbutton;
    ImageView leftimage, rightimage;

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

        rollbutton = (Button) findViewById(R.id.rollbutton);
        leftimage = (ImageView) findViewById(R.id.leftdice);
        rightimage = (ImageView) findViewById(R.id.rightdice);

        final int[] dicearray = {
                R.drawable.dice1,
                R.drawable.dice2,
                R.drawable.dice3,
                R.drawable.dice4,
                R.drawable.dice5,
                R.drawable.dice6,
        };

        rollbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                
                Random random_nu_generator = new Random();
                int random_no = random_nu_generator.nextInt(6);
                
                leftimage.setImageResource(dicearray[random_no]);

                int random_no_2 = random_nu_generator.nextInt(6);

                rightimage.setImageResource(dicearray[random_no_2]);
            }
        });
    }
}



xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/newbackground"
    tools:context="com.example.viraj.diceapp.MainActivity">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="250dp">

        <ImageView
            android:id="@+id/logoimage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            app:srcCompat="@drawable/dicee_logo" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/leftdice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/dice3" />

        <ImageView
            android:id="@+id/rightdice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/dice1" />
    </LinearLayout>

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:id="@+id/rollbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/button_text"
        android:textStyle="bold"
        android:background="#3F51B5"
        android:textColor="#FFEB3B"/>

    </RelativeLayout>
</LinearLayout>


Share:

RANDOM NUMBER GENERATOR CODE ANDROID



package com.example.viraj.diceapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.Random;

public class MainActivity extends AppCompatActivity {
    Button rollbutton;
    ImageView leftimage , rightimage;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        rollbutton=(Button) findViewById(R.id.rollbutton);
        leftimage=(ImageView)findViewById(R.id.leftdice);
        rightimage=(ImageView)findViewById(R.id.rightdice);
        rollbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               // Toast.makeText(getApplicationContext(),"HELLO",Toast.LENGTH_LONG).show();
                Random random_nu_generator=new Random();
               int random= random_nu_generator.nextInt(1999);
                Toast.makeText(getApplicationContext(),"RANDOM NO IS = " + "" +random,Toast.LENGTH_LONG).show();

            }
        });
    }
}

Share:

Saturday, 16 December 2017

to do app

package com.example.viraj.app_honey_do_list_sharedpreference;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class MainActivity extends AppCompatActivity {
    private Button button;
    private EditText editText_message;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText_message = (EditText) findViewById(R.id.id_entertext);
        button = (Button) findViewById(R.id.id_button);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //logic goes here
                if (!editText_message.getText().toString().equals("")) {
                    String message = editText_message.getText().toString();
                    writetofile(message);
                } else {
                    //do nothing for now
                }

            }
        });
        try {
            //-----------------------------
            if (readfromfile() != null) {
                editText_message.setText(readfromfile());
            }//----------------------------
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //------------------------
    private void writetofile(String message) {
        try {
            //-------------------------itna hi likha he
            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(openFileOutput("todolist.txt", Context.MODE_PRIVATE));
            outputStreamWriter.write(message);
            outputStreamWriter.close();//alwas close your stream
            //-----------------------------
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private String readfromfile() throws IOException {
        String result = "";
        InputStream inputStream = openFileInput("todolist.txt");

        if (inputStream != null) {
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            //we need buffer behav like a bucket
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            //empty string to to do things
            String tempstring = "";
            StringBuilder stringBuilder = new StringBuilder();
            //temp string me read hone jaayega
            while ((tempstring = bufferedReader.readLine()) != null) {
                stringBuilder.append(tempstring);
            }
            inputStream.close();
            result = stringBuilder.toString();
        }

        return result;
    }
}



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.viraj.app_honey_do_list_sharedpreference.MainActivity">

    <EditText
        android:id="@+id/id_entertext"
        android:layout_width="276dp"
        android:layout_height="282dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:hint="ENTER YOUT LIST"
        android:inputType="textMultiLine"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.084" />

    <Button
        android:id="@+id/id_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        tools:layout_editor_absoluteX="148dp"
        tools:layout_editor_absoluteY="406dp" />
</android.support.constraint.ConstraintLayout>

Share:

Friday, 15 December 2017

shared preferences in android

package com.example.viraj.sharedpreferences;

import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private Button savebutton;
    private EditText entertext;
    private TextView resultdisplay;
    private SharedPreferences myPref;
//information isme store kart he iss liy create kiya
    private static final String PREF_NAME = "MY_PREF_FILE";

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

        savebutton = (Button) findViewById(R.id.id_savedata);
        entertext = (EditText) findViewById(R.id.id_entersomething);
        resultdisplay = (TextView) findViewById(R.id.id_resulttextview);

        savebutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                myPref = getSharedPreferences(PREF_NAME, 0);
                SharedPreferences.Editor editor = myPref.edit();
//editor liya our save kiya
                editor.putString("key_messgae_ki_he", entertext.getText().toString());
                //save commit
                editor.commit();

            }

        });
//get data back
        SharedPreferences pref = getSharedPreferences(PREF_NAME, 0);//level o he
        if (pref.contains("key_messgae_ki_he")) {
            String message = pref.getString("key_messgae_ki_he", "not found");
            resultdisplay.setText("MESSAGE" + message);
        }

    }
}

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.viraj.sharedpreferences.MainActivity">

    <EditText
        android:id="@+id/id_entersomething"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="48dp"
        android:ems="10"
        android:hint="ENTER SOMETHING"
        android:inputType="textPersonName"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/id_savedata"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="52dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_entersomething" />

    <TextView
        android:id="@+id/id_resulttextview"
        android:layout_width="252dp"
        android:layout_height="28dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="60dp"
        android:text="TextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_savedata" />

    <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>


Share:

Sunday, 10 December 2017

MUSIC PLAYER APP


Share:

basic play mp3 part 3

package com.example.viraj.mediaplayerapp;

import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.Toast;

//import static com.example.viraj.mediaplayerapp.R.raw.ashique;

public class MainActivity extends AppCompatActivity {
    private MediaPlayer mediaPlayer;
    private Button playbutton;
    private SeekBar M_seekBar;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        M_seekBar = (SeekBar) findViewById(R.id.id_seekbar);
        mediaPlayer = new MediaPlayer();
        mediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.mercy);
        M_seekBar.setMax(mediaPlayer.getDuration());
//-------seekbar        M_seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override            public void onProgressChanged(SeekBar seekBar, int i_879, boolean b_123) {
                if (b_123) {
                    mediaPlayer.seekTo(i_879);
                }
            }

            @Override            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
        //----------------seekbar        //set on completion method-----------------        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override            public void onCompletion(MediaPlayer mediaPlayer_mp) {
                int duration = mediaPlayer_mp.getDuration();
                String mduration = String.valueOf(duration / 1000);
                Toast.makeText(getApplicationContext(), "Duration" + mduration, Toast.LENGTH_LONG).show();
            }
        });

        //----------------------------        playbutton = (Button) findViewById(R.id.MusicPlay);
        playbutton.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                if (mediaPlayer.isPlaying()) {
                    //stop music and give option                    pausemusic();
                } else {
                    startmusic();
                }
            }
        });

    }

    //create method in side of our class    public void pausemusic() {
        if (mediaPlayer != null)
            mediaPlayer.pause();
        playbutton.setText("PLAY MUSIC");
    }

    public void startmusic()

    {
        if (mediaPlayer != null) {
            mediaPlayer.start();
            playbutton.setText("PAUSE MUSIC");
        }

    }

    //memory consume karta he iss liye    @Override    protected void onDestroy() {
        if (mediaPlayer != null && mediaPlayer.isPlaying()) {
            mediaPlayer.stop();
            mediaPlayer.release();
            mediaPlayer = null;
        }
        super.onDestroy();
    }
}
Share:

basic play mp3 part 2

package com.example.viraj.mediaplayerapp;
import android.media.MediaPlayer;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.Toast;
//import static com.example.viraj.mediaplayerapp.R.raw.ashique;

public class MainActivity extends AppCompatActivity {
    private MediaPlayer mediaPlayer;
    private Button playbutton;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mediaPlayer = new MediaPlayer();
        mediaPlayer = MediaPlayer.create(MainActivity.this,R.raw.mercy);

       //set on completion method-----------------        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
    @Override    public void onCompletion(MediaPlayer mediaPlayer_mp) {
        int duration =mediaPlayer_mp.getDuration();
        String mduration=String.valueOf(duration/1000);
        Toast.makeText(getApplicationContext(),"Duration"+mduration,Toast.LENGTH_LONG).show();
    }
});

        //----------------------------
        playbutton = (Button) findViewById(R.id.MusicPlay);
        playbutton.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                if (mediaPlayer.isPlaying()) {
                    //stop music and give option                    pausemusic();
                }
                else                {
                    startmusic();
                }
            }
        });

    }
    //create method in side of our class    public void pausemusic() {
        if (mediaPlayer != null)
            mediaPlayer.pause();
        playbutton.setText("PLAY MUSIC");
    }

    public void startmusic()

    {
        if (mediaPlayer != null) {
            mediaPlayer.start();
            playbutton.setText("PAUSE MUSIC");
        }

    }//memory consume karta he iss liye    @Override    protected void onDestroy() {
       if (mediaPlayer!=null && mediaPlayer.isPlaying())
       {
           mediaPlayer.stop();
           mediaPlayer.release();
           mediaPlayer=null;
       }
        super.onDestroy();
    }
}
Share:

BASIC play mp3 android studio

create raw folder  value resource type raw select kare

package com.example.viraj.mediaplayerapp;

import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

//import static com.example.viraj.mediaplayerapp.R.raw.ashique;


public class MainActivity extends AppCompatActivity {
    private MediaPlayer mediaPlayer;
    private Button playbutton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mediaPlayer = new MediaPlayer();
        mediaPlayer = MediaPlayer.create(MainActivity.this,R.raw.haa);

        playbutton = (Button) findViewById(R.id.MusicPlay);
        playbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mediaPlayer.isPlaying()) {
                    //stop music and give option
                    pausemusic();
                }
                else
                {
                    startmusic();
                }
            }
        });

    }
    //create method in side of our class
    public void pausemusic() {
        if (mediaPlayer != null)
            mediaPlayer.pause();
        playbutton.setText("PLAY MUSIC");
    }

    public void startmusic()

    {
        if (mediaPlayer != null) {
            mediaPlayer.start();
            playbutton.setText("PAUSE MUSIC");
        }

    }
}



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.viraj.mediaplayerapp.MainActivity">

    <Button
        android:id="@+id/MusicPlay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="PLAY"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

Share:

Search This Blog

Popular Posts

Pages

how to make crores from 1 lakh in stock markets in 1 year

how to make crores from 1 lakh in stock markets in 1 year

Blogger Tutorials

Blogger Templates

Sample Text

Copyright © ANDROID TUTORIAL CODE | Powered by Blogger
Design by SimpleWpThemes | Blogger Theme by NewBloggerThemes.com & Distributed By Protemplateslab