--ADVERTISEMENT--

In this android tutorial, you will learn how to embed and play Mp3 music/song in android WebView application programmatically. If you want to play any music from the internet in your android app, the easiest and simplest way is to embed the music/song code and place that in your application using WebView.

If you have already embedded the YouTube video in your application using web view, exactly the same process we apply here.

There are many online music playing sites and they have the option to embed the songs. Here I have embedded a song from soundcloud.com, no matter you can embed songs from anywhere.

Related:
How to Embed YouTube Video in Android WebView
Android WebView Tutorial with Example
How to Convert Custom Website Design by Using Bootstrap into Android Application

Android Example: How to Embed and Play Mp3 Songs/Music in Android WebView


This example gives you step by step guide to embed and play songs from the internet using webview in your app. Following is the code of java activity file and XML layout file.

XML Layout File


In this XML layout file I have added a WebView inside LinearLayout and given an id name. Following is the complete content of XML layout file.

res/layout/embed_and_play_songs_in_android.xml

Java Activity File


Following is the complete codes of java activity file where I have added the iframe code of embed music/song to a string. Also I have created a WebView client, settings enabled JavaScript and load the music iFrame string in the WebView.

src/ EmbedPlaySongsAndroid.java

AndroidManifest.xml File


In your app AndroidManifest.xml file you have to add a line of permission to the internet because we have loaded the music from internet. Your application AndroidManifest.xml file will look like this.

AndroidManifest.xml

Strings.xml File


res/values/strings.xml

Android Example: How to Embed and Play Mp3 Songs/Music in Android WebView

You have done all things. Now run your Embed and Play MP3 Songs/Music in Android Application Using WebView app, you will see a music player with play button; click the play icon to play music. Make sure you have internet connection in the device. If you have any question, feel free to post in the comment box below.

Post a Comment

Powered by Blogger.