I was thinking how i create android audio streaming apps? begin to searching tutorial in google. And i find tutorial from Joyce Echessa. This ladies create Audio Streaming Apps that accesses soundcloud API. now, I am trying to create same application but use Clyp API. Because Clyp API is simpler than the Soundcloud API. 👌
So first of all you need to register an account on the Clyp. Once you've created an account, upload your audio file to the Clyp with your account. After the upload is complete, remember your id file. Where i get my file id?. We can find at detail Clyp in tab url browser or field direct link in Clyp.
We’ll now create the Android app. Create a new Android project in Android Studio. Set your own company domain and click on Next. On the next screen I left the Minimum SDK at the default of API 17. Choose the Navigation Drawer Activity or Empty Activity template on the next screen and on the last screen click finish.
Next open your app's build.gradle file and add the gson, retrofit, converter-gson.
Add the following dependencies library to the file (build.gradle).
When you change the build.gradle file, a message will let you know that a Sync is needed for the IDE to work correctly. Click on Sync Now to the right of that message. Gradle will fetch the dependencies added. You'll need an internet connection for Gradle to fetch them.
To start off, create a class that will hold some configuration data like base URL for Clyp endpoints and Retrofit. Create a class named Apiclient and modify it as shown.
The BASE_URL is base URL for API endpoints as stated in this Clyp API Documentation. if you want to know what can be done with the API, the reference guide is a good resource to read.
Next create a streaming request object that will hold the data for audio file fetched from Clyp. Create a class called StreamingRequest add the following fields and getter methods.
In the above code, we create twelve fields that will hold the track data we are interested in. To know what data a call to the API will receive, you can try out following URL in your browser. It fetches a single track’s data in JSON format.
In the StreamingRequest class, notice the @SerializedName annotations on each field and the gson import. The Gson library is an open source library from Google that serializes and deserializes Java objects to (and from) JSON. Above, it’ll take the JSON fetched and map it to the object’s fields, otherwise you would have to write a lot more code to grab the data from JSON and create a StreamingRequest object with it.
Open the AndroidManifest.xml file and add the following permission.
Next add an Interface to the project called ApiInterface. Modify it as shown.
Next in MainActivity. Modify it as shown.
And the last at MainActivity SetContentView or in xml (activity_main.xml). Modify it as shown.
Full source code, you can download from my Github.
Sign up here with your email



1 comments:
Write commentsI have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates.
ReplyMusic streaming
ConversionConversion EmoticonEmoticon