1. Download our Official Android App: Forums for Android!

App Inventor Converting Activity into Fragment

Discussion in 'Android Development' started by saurabh28, Sep 9, 2017.

  1. saurabh28

    saurabh28 Lurker
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    6
    Joined:
    Sep 8, 2017

    Sep 8, 2017
    6
    1
    16
    Male
    India
    Please anyone convert this Activity into a Fragment,

    PlayMusic.java

    package com.playonlineaudiomp3_android_examples.com;

    import java.io.IOException;
    import java.util.Timer;

    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.media.AudioManager;
    import android.media.MediaPlayer;
    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;
    import android.view.View;
    import android.widget.Button;
    import android.widget.SeekBar;


    public class MainActivity extends FragmentActivity {

    Button buttonStop,buttonStart,buttonPause ;

    String AudioURL = "http://www.singhsahib.com/sukhmani-sahib/sukhmanisahib-a.mp3";

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

    buttonStart = (Button)findViewById(R.id.button1);
    buttonStop = (Button)findViewById(R.id.button2);
    buttonPause = (Button)findViewById(R.id.button3);


    mediaplayer = new MediaPlayer();
    mediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    buttonStart.setOnClickListener(new View.OnClickListener() {

    @override
    public void onClick(View v) {
    // TODO Auto-generated method stub

    try {

    mediaplayer.setDataSource(AudioURL);
    mediaplayer.prepare();


    } catch (IllegalArgumentException e) {

    // TODO Auto-generated catch block
    e.printStackTrace();

    } catch (SecurityException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();

    } catch (IllegalStateException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();

    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();

    }

    mediaplayer.start();


    }
    });

    buttonStop.setOnClickListener(new View.OnClickListener() {

    @override
    public void onClick(View v) {
    // TODO Auto-generated method stub


    mediaplayer.stop();


    }
    });

    buttonPause.setOnClickListener(new View.OnClickListener() {

    @override
    public void onClick(View v) {
    // TODO Auto-generated method stub


    mediaplayer.pause();


    }
    });


    }

    }
     

    Advertisement

Share This Page

Loading...