Audio Streaming in Sketchware



Hello viewers today in this topic I'll show to you about audio streaming with database URL in Sketchware. 

1. Create a new project. In this new project enable Firebase manager with necessary data.

2. In Main activity add two button. Button 1 is for upload audio files and button two is for playing files & a seekbar for getting progress of the music




3. Now go to component area and add Firebase Storage for uploading files, Firebase Auth for avoiding error in Sketchware new version, media player is for playing audio, Filepicker for picking files & timer for set progress in seekbar




4. Now go to on button click listener and set file picker pick files


5. Go to component area and add event "on file picked", in "on file picked" create a string variable name "filePath" and set it to "get at (0) of [Listring Filepath]" and upload this file with firebase storage component.


6. Add "on upload success" event for that component, and create string "URL" for getting url of uploaded file like this:

7. Now go to activity and set when button 2 on click > create media player with URL. And set media player to start, then set timer after 0 to every 20 ms, seekbar progress to current duration & max to song duration.

Code:mp = new MediaPlayer();
mp.setAudioStreamType(3);
try {
	mp.setDataSource(URL);
} catch (IllegalArgumentException e) {
	Toast.makeText(getApplicationContext(), "Unknown URL!", 1).show();
} catch (SecurityException e2) {
	Toast.makeText(getApplicationContext(), "Unknown URL!", 1).show();
}
catch (IllegalStateException e3) {
	Toast.makeText(getApplicationContext(), "Unknown URL!", 1).show();
}
catch (java.io.IOException e4) {
e4.printStackTrace();
}try {
	mp.prepare();
} catch (IllegalStateException e5){
	Toast.makeText(getApplicationContext(), "Unknown URL!", 1).show();
}catch (java.io.IOException e6){
	Toast.makeText(getApplicationContext(), "Unknown URL!", 1).show();
}



That's all save & run your project   




No comments:

Note: Only a member of this blog may post a comment.

Powered by Blogger.