Developing a Music Streaming Android App

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.

 

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

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




like.php

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.

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

song_layout.xml

fragment_comn.xml

MainActivity.java which contains methods for streaming

activity_main.xml

Constants.java

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

color.xml

icon_dislike.xml

icon_like.xml

icon_none.xml

icon_play.xml

pause.xml

Pause button used for pause streaming audio.

 

play.xml

Play button used for start streaming.

Leave a Reply

%d bloggers like this: