Developing a Music Streaming Android App

streaming logicchip 1

For creating a audio streaming in android you must be aware of some things. Mainly database,web service,json array,php things like that. This project can be tricky. However Wamp is used as the server for php and database. Advantage of using php is it’s very easy to setup and test. Android support streaming defaultly. Only need to set type AudioManager.STREAM_MUSIC in MediaPlayer object.


MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

Here a tablayout is used for category selection. Here we use 6 tabs Blues, Electronics, Folk, Hip Hop, Jazz, Pop and Rock. For database connection we use web services the server side code is in php. Only one fragment is used for all the 6 tabs, changing content according to the tab. Inorder to use web services we need a network library called volley, Add this dependencies in the build.gradle(Module:app) file


dependencies {
compile 'com.android.volley:volley:1.0.0'
}




Also add internet permission in Androidmanifest.xml.

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

 

1. Creating Database

Download wamp or xamp server and install it. Create a database called song in it a table called audio.

streaming logicchip 2

Now create a folder called song in the www directory of wamp or xamp whatever you are installed. Another folder called songs inside song to store your music files in there. Example a.mp3, b.mp4 etc. Add those names to the database also.

streaming logicchip 3

If wamp or xamp don’t run properly check Internet Information Service(IIS) Manager in windows. Also check privileges.

 

2. Php files for web service

Need two php files like.php and song.php. The song.php file is for finding and viewing songs. The like.php file is for rating the audio file.

song.php

<?php
$host="localhost"; // Host name
$servername = "localhost";
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="song"; // Database name

$conn = new mysqli($servername, $username, $password,$db_name);
$tname=$_POST['tag'];

// Check connection
if ($conn->connect_error) {
    	die("Connection failed: " . $conn->connect_error);
} else{
//echo "Connected successfully "."<br />\r\n";
}
	$jsonData      = array();
	$jsonTempData  = array();
$sql = "SELECT * FROM `audio` WHERE TYPE='$tname'";//" ORDER BY index DESC";
	$result = $conn->query($sql);

if ($result->num_rows > 0) {
while(($rowb = $result->fetch_assoc())) {
			$jTempData  = array();
      		$jTempData['id']         	=$rowb["NO"];
			$jTempData['name']         	=$rowb["NAME"];
      		$jTempData['score']         =$rowb["SCORE"];
      		$jTempData['rate']         	=$rowb["RATING"];
			$jsonData[]=$jTempData;
	}
	}else {
			$jTempData  = array();
    			$jTempData['id']         	="no";
			$jTempData['song']         	="noooo";
      		$jTempData['song']         	="noo";
      		$jTempData['song']         	="no";
			$jsonData[]=$jTempData;
}
$conn->close();

$outputArr['song'] = $jsonData;
// Encode Array To JSON Data
print_r( json_encode($outputArr));
?>

For song.php we must provide a tag. Tag for the category of songs to be selected and displayed.




like.php

<?php
$servername = "localhost";// Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="song"; // Database name

$conn = new mysqli($servername, $username, $password,$db_name);
$id=$_POST['id'];
$val=$_POST['like'];

// Check connection
if ($conn->connect_error) {
    		die("Connection failed: " . $conn->connect_error);
} else{
//echo "Connected successfully "."<br />\r\n";
}
	$jsonData      = array();
	$jsonTempData  = array();
  	$sql = "UPDATE audio SET SCORE=SCORE+'$val' WHERE NO='$id'";
	$result = $conn->query($sql);
  	$jTempData['song']         	=$result;
  	$jsonData[]=$jTempData;
  	$conn->close();

  	$outputArr['song'] =$jsonData;
  // Encode Array To JSON Data
  	print_r( json_encode($outputArr));
  ?>

For like.php we must provide id and value of rating. Updated rating can be positive or negative.

 

3. Android part

Class files for android part are MainActivity.java, Constants.java and Common.java. MainActivity holds the fragments and tabs. Also it’s where the streaming take place. Constants.java for holding the constants. Common.java for fragment class and a page adapter class for the tabs.

Comn.java

Class file comn.java contains clicks for streaming audio. Load streaming audio list and display  it.

public class Comn extends Fragment {
    int sect;
    public ListView listView;
    public static ArrayList<String> id = null, song = null, score = null, rate = null;
    public SongAdapter songAdapter;
    public RequestQueue requestQueue;

    public Comn() {

    }

    public Comn newInstance(int sectionNumber, MediaPlayer mediaPlayer) {

        Comn fragment = new Comn();
        Bundle args = new Bundle();
        args.putInt(Constants.KEY_NUMBER, sectionNumber);
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        requestQueue = ((MainActivity) getActivity()).getRequestQueue();
        requestQueue.getCache().clear();
        View rootView = inflater.inflate(R.layout.fragment_comn, container, false);
        TextView textView = (TextView) rootView.findViewById(R.id.t1);
        listView = (ListView) rootView.findViewById(R.id.listview_song);
        listOfSong();
        //((MainActivity)getActivity()).Snack("Json pling");
        textView.setText(getString(R.string.section_format, getArguments().getInt(Constants.KEY_NUMBER)));
        return rootView;
    }


    public void listOfSong() {

        StringRequest menuRequest = new StringRequest(Request.Method.POST, Constants.LINK,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONArray jsonResponse = new JSONObject(response).getJSONArray(Constants.KEY);
                            int i = jsonResponse.length();

                            id = new ArrayList<String>();
                            song = new ArrayList<String>();
                            score = new ArrayList<String>();
                            rate = new ArrayList<String>();

                            for (int j = 0; j < i; j++) {
                                JSONObject jsonChildNode = jsonResponse.getJSONObject(j);

                                id.add(jsonChildNode.optString(Constants.TAG_ID).toString());
                                song.add(jsonChildNode.optString(Constants.TAG_NAME).toString());
                                score.add(jsonChildNode.optString(Constants.TAG_SCORE).toString());
                                rate.add(jsonChildNode.optString(Constants.TAG_RATE).toString());

                            }
                            songAdapter = new SongAdapter(getActivity(), id, song, score, rate);
                            listView.setAdapter(songAdapter);


                        } catch (JSONException e) {
                            e.printStackTrace();
                            ((MainActivity) getActivity()).Snack("Json " + e.getMessage());
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        error.printStackTrace();
                        ((MainActivity) getActivity()).Snack("Volley " + error.getMessage());
                    }
                }
        ) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<>();
                // the POST parameters:
                params.put(Constants.C_TAG, getResources().obtainTypedArray(R.array.type).getText(getArguments().getInt(Constants.KEY_NUMBER)).toString());
                return params;
            }
        };
        //requestQueue.getCache().clear();
        requestQueue.add(menuRequest);
    }


    public class SongAdapter extends BaseAdapter {
        Activity activity;
        ArrayList<String> id, name, score, rate;


        public SongAdapter(Activity activity, ArrayList<String> id, ArrayList<String> name, ArrayList<String> score, ArrayList<String> rate) {
            this.activity = activity;
            this.id = id;
            this.name = name;
            this.score = score;
            this.rate = rate;
        }

        public class ViewHolder {
            public TextView song_name, song_rating;
            public ImageView rate_l, rate_d, rate_p;
        }


        @Override
        public int getCount() {
            return name.size();
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            View vi = convertView;
            ViewHolder holder = null;
            if (convertView == null) {
                LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = inflater.inflate(R.layout.song_layout, null);
                holder = new ViewHolder();
                holder.song_name = (TextView) convertView.findViewById(R.id.song_name);
                holder.song_rating = (TextView) convertView.findViewById(R.id.song_rating);
                holder.rate_l = (ImageView) convertView.findViewById(R.id.rate_l);
                holder.rate_d = (ImageView) convertView.findViewById(R.id.rate_d);
                holder.rate_p = (ImageView) convertView.findViewById(R.id.rate_p);

                holder.song_name.setText(name.get(position));
                holder.song_rating.setText(score.get(position));

                holder.rate_p.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((MainActivity) activity).playSong(name.get(position));
                    }
                });
                holder.rate_l.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((MainActivity) activity).like(id.get(position), "1");
                        listOfSong();
                    }
                });

                holder.rate_d.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        ((MainActivity) activity).like(id.get(position), "-1");
                        listOfSong();
                    }
                });

                convertView.setTag(holder);
            } else {

                holder = (ViewHolder) convertView.getTag();
                holder.song_name.setText(name.get(position));
                holder.song_rating.setText(score.get(position));

            }

            return convertView;
        }
    }
}

Adapter for viewing songs is inside the comn.java class, It uses an xml file for Ui.

song_layout.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">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text.mp3"
        android:id="@+id/song_name" />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="right">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:layout_gravity="center_vertical"
            android:text="123456"
            android:id="@+id/song_rating" />
        <View
            android:layout_width="24dp"
            android:layout_height="24dp"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon_play"
            android:tint="@color/black"
            android:id="@+id/rate_p"
            android:layout_gravity="center_vertical"/>
        <View
            android:layout_width="24dp"
            android:layout_height="24dp"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon_like"
            android:tint="@color/green_500"
            android:id="@+id/rate_l"
            android:layout_gravity="center_vertical"/>
        <View
            android:layout_width="24dp"
            android:layout_height="24dp"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon_dislike"
            android:tint="@color/red_500"
            android:id="@+id/rate_d"
            android:layout_gravity="center_vertical"/>
    </LinearLayout>


</LinearLayout>

fragment_comn.xml

<FrameLayout 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"
    tools:context="logicchip.cheriyidam.songstream.Comn">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/t1"
        android:visibility="gone"
        android:text="common" />
    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listview_song">

    </ListView>

</FrameLayout>

MainActivity.java which contains methods for streaming

public class MainActivity extends AppCompatActivity {


    private SectionsPagerAdapter mSectionsPagerAdapter;
    private ViewPager mViewPager;
    public MediaPlayer mediaPlayer;
    public String songString="";
    public boolean intialStage = true,playPause;
    public CoordinatorLayout coordinatorLayout;
    TextView sng_name,sng_dur;
    public int dur;
    public RequestQueue requestQueue;
    public ImageView img;

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

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        requestQueue= Volley.newRequestQueue(MainActivity.this);
        requestQueue.getCache().clear();
        mViewPager = (ViewPager) findViewById(R.id.container);
        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
        coordinatorLayout=(CoordinatorLayout)findViewById(R.id.main_content);
        sng_name=(TextView)findViewById(R.id.sng_name);
        sng_dur=(TextView)findViewById(R.id.sng_dur);
        img=(ImageView)findViewById(R.id.icon_img);
        img.setEnabled(false);
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

        tabLayout.addTab(tabLayout.newTab().setText("Blues"));
        tabLayout.addTab(tabLayout.newTab().setText("Electronic"));
        tabLayout.addTab(tabLayout.newTab().setText("Folk"));
        tabLayout.addTab(tabLayout.newTab().setText("Hip hop"));
        tabLayout.addTab(tabLayout.newTab().setText("Jazz"));
        tabLayout.addTab(tabLayout.newTab().setText("Pop"));
        tabLayout.addTab(tabLayout.newTab().setText("Rock"));
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(),tabLayout.getTabCount(),mediaPlayer);
        mViewPager.setAdapter(mSectionsPagerAdapter);
       // tabLayout.setupWithViewPager(mViewPager);
        mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                mViewPager.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mediaPlayer.isPlaying()){
                    playPause=true;
                    mediaPlayer.pause();
                    img.setImageResource(R.drawable.play);
                    img.setColorFilter(getResources().getColor(R.color.black));
                }else if(playPause){
                    mediaPlayer.start();
                    img.setImageResource(R.drawable.pause);
                    img.setColorFilter(getResources().getColor(R.color.black));
                    playPause=false;
                }
            }
        });
    }
    public RequestQueue getRequestQueue(){
        return requestQueue;
    }

    public void like(final String id, final String like){
        StringRequest menuRequest = new StringRequest(Request.Method.POST, Constants.LIKE,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONArray jsonResponse = new JSONObject(response).getJSONArray(Constants.KEY);
                            int i=jsonResponse.length();


                            for(int j=0;j<i;j++){
                                JSONObject jsonChildNode = jsonResponse.getJSONObject(j);
                                Snack(jsonChildNode.optString(Constants.TAG_SONG).toString());

                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                            Snack("Json "+e.getMessage());
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        error.printStackTrace();
                        Snack("Volley "+error.getMessage());
                    }
                }
        ) {
            @Override
            protected Map<String, String> getParams()
            {
                Map<String, String>  params = new HashMap<>();
                // the POST parameters:
                params.put(Constants.TAG_ID,id);
                params.put(Constants.TAG_LIKE,like);
                return params;
            }
        };
        //requestQueue.getCache().clear();
        requestQueue.add(menuRequest);
    }


    public MediaPlayer getMediaPlayer(){
        return mediaPlayer;
    }

    public void list(){
    }

    public void playSong(String song) {
        sng_name.setText(song);
        img.setEnabled(true);
        String songPath=Constants.SONG_LINK+song;

        //    Snack(songPath);
       try {

            if(mediaPlayer.isPlaying()){
                if(songString.equals(songPath)){
                    mediaPlayer.pause();
                    playPause=true;
                    img.setImageResource(R.drawable.play);
                    img.setColorFilter(getResources().getColor(R.color.black));
                }else{
                    playPause=false;
                    mediaPlayer.stop();
                    mediaPlayer.reset();
                    mediaPlayer.setDataSource(songPath);
                    songString=songPath;
                    mediaPlayer.prepare();
                    mediaPlayer.start();

                    //setting duration change it...
                    sng_dur.setText(String.valueOf(mediaPlayer.getDuration()));

                    img.setImageResource(R.drawable.pause);
                    img.setColorFilter(getResources().getColor(R.color.black));
                }
            }else if(playPause){
                if(songString.equals(songPath)){
                    mediaPlayer.start();
                    img.setImageResource(R.drawable.pause);
                    img.setColorFilter(getResources().getColor(R.color.black));
                    playPause=false;
                }else{
                    playPause=false;
                    mediaPlayer.stop();
                    mediaPlayer.reset();
                    mediaPlayer.setDataSource(songPath);
                    songString=songPath;
                    mediaPlayer.prepare();
                    mediaPlayer.start();

                    //setting duration change it...
                    sng_dur.setText(String.valueOf(mediaPlayer.getDuration()));

                    img.setImageResource(R.drawable.pause);
                    img.setColorFilter(getResources().getColor(R.color.black));
                }

            }else {
                mediaPlayer.reset();
                playPause=false;
                mediaPlayer.setDataSource(songPath);
                songString=songPath;
                mediaPlayer.prepare();
                mediaPlayer.start();
                sng_dur.setText(String.valueOf(mediaPlayer.getDuration()));
                img.setImageResource(R.drawable.pause);
                img.setColorFilter(getResources().getColor(R.color.black));
               // dur=mediaPlayer.getDuration();
                //Snack(String.valueOf(dur));
            }


            // Setup listener so next song starts automatically
            mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

                public void onCompletion(MediaPlayer arg0) {
                    mediaPlayer.stop();
                    mediaPlayer.reset();
                }

            });

        } catch (IOException e) {
            Log.v(getString(R.string.app_name), e.getMessage());
        }
    }

    public void check(){

    }


    public  void Snack(String message) {
        Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG).setAction("Action", null).show();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    
  

}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="logicchip.cheriyidam.songstream.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:layout_scrollFlags="scroll|enterAlways">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="30dp" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:visibility="gone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="end|bottom">
        <ImageView
            android:layout_margin="@dimen/appbar_padding_top"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/icon_img"
            android:layout_gravity="center_vertical"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/green_500"
            android:layout_margin="@dimen/appbar_padding_top"
            android:layout_gravity="center_vertical"
            android:id="@+id/sng_name"/>
        <View
            android:layout_width="60dp"
            android:layout_height="2dp"
            android:layout_gravity="center_vertical"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/red_500"
            android:layout_margin="@dimen/appbar_padding_top"
            android:layout_gravity="center_vertical"
            android:id="@+id/sng_dur"/>
    </LinearLayout>


</android.support.design.widget.CoordinatorLayout>

Constants.java

public class Constants {
    public static final String KEY_NUMBER = "key_number";
    public final static String IP="http://192.168.201.1";
    public final static String LINK="http://192.168.201.2/song/song.php";
    public final static String LIKE="http://192.168.201.2/song/like.php";
    public final static String SONG_LINK="http://192.168.201.2/song/songs/";
    public final static String KEY="song";

    public final static String TAG_ID="id";
    public final static String TAG_LIKE="like";
    public final static String TAG_NAME="name";
    public final static String TAG_SCORE="score";
    public final static String TAG_RATE="rate";
    public final static String TAG_SONG="song";

    public final static String C_TAG="tag";
}

You should replace the ip address with your wamp server running systems ip. Streaming requires ip or link for working. While using a local system ip is our best option. Don’t use “localhost” us ip. Streaming works by loading a link and retrieving it’s content. By using a localhost android try to access it which is not possible, because it’s not have any servers running. Wamp is the server running so we need to use the ip of the system. In case it’s hosted online server. We can use links like “www.yourwebsite.com/songlink.mp3” .

SectionsPagerAdapter.java

public class SectionsPagerAdapter extends FragmentPagerAdapter {
    public MediaPlayer mediaPlayer;
    int mNumOfTabs;

    public SectionsPagerAdapter(FragmentManager fm,int NumOfTabs,MediaPlayer mediaPlayer) {
        super(fm);
        this.mediaPlayer=mediaPlayer;
        this.mNumOfTabs = NumOfTabs;
    }

    @Override
    public Fragment getItem(int position) {
        Comn comn=new Comn();
        return comn.newInstance(position,mediaPlayer);

    }

    @Override
    public int getCount() {
        return mNumOfTabs;
    }
}

color.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>

    <color name="red_500">#F44336</color>
    <color name="green_500">#4CAF50</color>
    <color name="white">#FFF</color>
    <color name="black">#000</color>
</resources>

icon_dislike.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
</vector>

icon_like.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
</vector>

icon_none.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M22,9.24l-7.19,-0.62L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21 12,17.27 18.18,21l-1.63,-7.03L22,9.24zM12,15.4l-3.76,2.27 1,-4.28 -3.32,-2.88 4.38,-0.38L12,6.1l1.71,4.04 4.38,0.38 -3.32,2.88 1,4.28L12,15.4z"/>
</vector>

icon_play.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M8,5v14l11,-7z"/>
</vector>

pause.xml

Pause button used for pause streaming audio.

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="50dp"
        android:height="50dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M6,19h4L10,5L6,5v14zM14,5v14h4L18,5h-4z"/>
</vector>

 

play.xml

Play button used for start streaming.

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="50dp"
        android:height="50dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M8,5v14l11,-7z"/>
</vector>

2 comments on “Developing a Music Streaming Android App

  1. Hello good morning, I am writing to you from Peru, do not list or reproduce anything, could you share your code with me, thank you

    1. It appears that i have lost those related to music streaming app, all that remain is the content of this blog.You can recreate the entire app by using this blog post.

Leave a Reply

%d bloggers like this: