I have a dropbox media server that has a collection of mp3 files that I want to stream onto an android application.
I know that using the "MediaPlayer" is the best way to go in the API.
How my main concern is how do I automate the process, where music is being played one after another? As if it was like an internet radio app?
Could someone please point me in the correct location for guides or display example code would be great thank you in advance.
Place the music files names in an arraylist (e.g songs) then implement onCompletionListener then set it to your media player. Inside the listener restart the media player to play the next item.
myMediaPlayer.setOnCompletionListener(this);
public void onCompletion(MediaPlayer arg0) {
arg0.release();
if (counter < songs.size()) {
counter++;
arg0 = MediaPlayer.create(getApplicationContext(), songs.get(counter);
arg0.setOnCompletionListener(this);
arg0.start();
}
}
If the server gives apps audio files;put the files in a queue and play them using mediaplayer or another audio player.
Get first song from server and start playing it, meanwhile continue downloading other songs one by one.
Related
I have a music player app which consists of a "playlist" and a "now playing" activity.
The two activities are linked using a menu for navigation.
When I select a song from the playlist is plays as expected in the background - I can go to the playlist and browse other songs...
However when I then use the menu to return to the now playing activity, it restarts the media file instead of just resuming? Surely it would just continue playing?
The below logic is inside of the onCreate() method but I have a feeling I should add to the onResume() method too?
Any assistance will be greatly appreciated!
--
if (itemSelected || !mMediaPlayer.isPlaying()){ //Gets media as normal
infoSetter();
musicPlayer();
} else if (!itemSelected && !mMediaPlayer.isPlaying()) { //Sets defaults if activity is accessed without making a selection
defaultInfoSetter();
defaultMusicPlayer();
} else if (mMediaPlayer.isPlaying()){ //TODO: Fix this part
//???????????????
}
I want to get MediaMetadata (song title / artist) from the current playing android audio source for any app (spotify, google play, soundcloud, YouTube, blackplayer, etc) and am trying to use MediaMetadataRetriever.setDatSource
Currently I have a function 'getActiveNotifications' in 'MainActivity.java' that gets called whenever a button is pressed, my code looks like this:
public void getActiveNotifications(View view) {
String temp ="temp";
Log.i("myTag", "Logging active notifications:");
//get data from MediaMetaData somehow? Always displays correct string in Logcat
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
//mmr.setDataSource("CURRENT APP PLAYING MUSIC (googlePlay / Spotify / Soundcloud etc)");
mmr.setDataSource("https://somewebsite.com/somefile.mp3", new HashMap<String,String>());
//extract metadata and save to string
String albumName = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
Log.i("myTag", "done with function. ");
}
Can I use .setDatSource generally for any music app or does it work for files only?
I can see updateMediaMetaData in Logcat printing media metadata of the currently playing song working for both music streaming and file playing apps (see pic)
Am I on the correct track here? Is there a way I can use .getDataSource on streaming / fileplayer apps for whatever the currently playing audio source is?
any help much appreciated, thanks
I'm creating a music visualiser. I am stuck on the part which allows the user to upload music tracks from their music library on their computer and have the visualiser respond to the beat of the specific song they have chosen.
I have used the minim library in Processing however I have to load the file name in the coding. I would like a way to have the user click a button which will open the file browser and allow them to select a track and then input that track into the player which will play the track and have the visualiser respond to the beats of the track.
I am not asking for code; rather I am asking on a way to go about this step by step. I am stuck on how to retrieve the files from the computer. I am not very good at coding so I am looking at libraries and tutorials online however; the videos I am finding on this topic only shows how to load text files into a sketch rather than a music file.
Sounds like you're looking for the selectInput() function.
From the reference:
void setup() {
selectInput("Select a file to process:", "fileSelected");
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User selected " + selection.getAbsolutePath());
}
}
Opens a platform-specific file chooser dialog to select a file for
input. After the selection is made, the selected File will be passed
to the 'callback' function. If the dialog is closed or canceled, null
will be sent to the function, so that the program is not waiting for
additional input. The callback is necessary because of how threading
works.
i am creating a mediaplayer app which is supposed to stream mp3 files from remote url.the problem is that the everything works fine on the codename one simulator but not on an actual android device.I want the app to show native player controls like on the simulator.below is my code and screenshots
try {
video = MediaManager.createMedia(sample_url,true);
Display.getInstance().callSerially(() -> {
if (mp != null){
mp.getMedia().cleanup();
}
Image samp = theme.getImage("sample.png");
Label samlabel = new Label();
samlabel.setIcon(samp);
mp = new MediaPlayer(video);
mp.setAutoplay(false);
video.setNativePlayerMode(true);
sample.add(BorderLayout.CENTER,BorderLayout.centerAbsolute(samlabel));
sample.add(BorderLayout.SOUTH,mp);
//songDetails.add(mp);
});
the first image is the simulator screenshot and the second image is the actual android device screenshot
It's unclear from your post if this is an mp3 which is audio and doesn't have media control or an actual video. The MediaPlayer class is strictly for video and you passed true to indicate that this is a video file so I'll treat it as such.
Notice that if this is an audio file then you need to add/create your own controls and shouldn't use the MediaPlayer class.
We recently defined behaviors for native media control rendering as explained here.
Just use:
video.setVariable(Media.VARIABLE_NATIVE_CONTRLOLS_EMBEDDED, true);
I've looked on Google for a while, searching how to play audio files, and most of the sources I found were with using java.applet.*, but I am trying to look for a way I can put it inside my actionPerformed() method.
public void actionPerformed(ActionEvent event) {
if(event.getActionCommand().equals("Play")){
//Short Audio File Playing Here
}
}
See the JavaSound info. page for the "Playing a Clip" section.
You may learn and use javax.sound API. Have a look at tutorial - Playing Back Audio.