Parsing logcat output on android phone [duplicate] - java

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

Related

when clicking on the fab button how to play the last played video in video player?

Actually, I'm Developing a Video player. then I have small Requirement for the video player i.e., whenever my video player application is launched when clicking on the fab button how to play the last played video? Please anyone can help me..
Hai Priyank Actually How to Add the Volume Increase and Decrease options using seekbar on Swipeup(); and swipe down on onToucheventListener. I have no idea to add the above functionality if possible please tell me the process or please provide the sample Priyank.
Store your last played video uri or file path some where in shared preference or in database.
and on click play that uri or file in your video view. like below example
Ask anything if you not getting my point.
Store last Video :
SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref",0);
Editor editor = pref.edit();
editor.putString("LastVideo", "path or Uri"); // Store your last video uri or file path
editor.commit();
Get last video :
String path = pref.getString("LastVideo", null); // getting String
You will get you last uri or path into path variable.

codename one mediaplayer not working on android device

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);

Android Radio App that streams my mp3 from a dropbox server

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.

How to make Android Gallery or Photos see videos taken by custom video app

I've written an Android app that is a simpler version of the stock camera. It only records video.
Despite this being a custom app, I'd like to have the videos recorded by this be easily visible from the Photos and Gallery apps.
I was under the impression that this is what the "MediaScannerConnection" class is for. I've found common advice that shows how to use this in either a "sendBroadcast" mode, or a more manual "scanFile" approach. I've implemented both of these options and found that they appear to have no effect. When I stop the recorder, a valid video is stored (I can play it from a file browser afterwards), but neither Photos or Gallery is made aware of the new video.
I've been storing the videos in files like "/storage/emulated/0/DCIM/Camera/20151223_150115.mp4". That directory also contains videos taken by the stock camera app. The base path was obtained from "Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)". I originally tried replacing "Camera" with a directory name based on the name of my app, but as that wasn't working (Photos/Gallery not seeing it, despite it being stored properly), I decided to try storing them where the stock videos are stored. That isn't working either.
My test device is a Galaxy Note 3, running Android 5.0.
My first attempt at using MediaScannerConnection was with this:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + outputFilePath)));
One of the values of "outputFilePath" is exactly the path shown above.
As this didn't appear to do anything, I then later tried this:
new SingleMediaScanner(getApplicationContext(), new File(outputFilePath));
Where "SingleMediaScanner" is this:
public static class SingleMediaScanner implements MediaScannerConnection.MediaScannerConnectionClient {
private MediaScannerConnection mMs;
private File mFile;
public SingleMediaScanner(Context context, File f) {
mFile = f;
mMs = new MediaScannerConnection(context, this);
mMs.connect();
}
#Override
public void onMediaScannerConnected() {
mMs.scanFile(mFile.getAbsolutePath(), "image/*");
}
#Override
public void onScanCompleted(String path, Uri uri) {
mMs.disconnect();
}
}
I tried running the last implementation in the debugger, and I saw it get to "onScanCompleted", but neither of the aforementioned apps see the new video.
Update:
With the current implementation, the "onScanCompleted" callback method gets called with "path" and "uri" parameters, which have the following values:
path: /storage/emulated/0/DCIM/Camera/20151223_194434.mp4
uri.toString(): content://media/external/file/106639
Uri.fromFile(new File(Path)): file:///storage/emulated/0/DCIM/Camera/20151223_194434.mp4

LibVLC fails to show subtitles for streamed video

I tried to create a video player on android device, which could stream videos from local server. I found an this example. I followed to the guideline and at the end I was able to play local video on my device. Then I started to modify this project. I set VideoActivity as launcher activity and commented out all data received from previous activity. I modified initialization of media from
Media m = new Media(libvlc, media);
mMediaPlayer.setMedia(m);
to
Uri uri = Uri.parse("http://samples.mplayerhq.hu/MPEG-4/embedded_subs/1Video_2Audio_2SUBs_timed_text_streams_.mp4");
Media m = new Media(libvlc, uri);
mMediaPlayer.setMedia(m);
Added 2 new methods (as you see, those methods are dummy methods simply to see the result)
private void setSubtitles(){
MediaPlayer.TrackDescription[] tds = mMediaPlayer.getSpuTracks();
mMediaPlayer.setSpuTrack(tds[tds.length - 1].id);
}
private void seekTo(long time) {
mMediaPlayer.setTime(time);
}
And called them on play event
#Override
public void onEvent(MediaPlayer.Event event) {
VideoActivity player = mOwner.get();
switch(event.type) {
case MediaPlayer.Event.EndReached:
Log.d(TAG, "MediaPlayerEndReached");
player.releasePlayer();
break;
case MediaPlayer.Event.Playing:
---> player.seekTo(1000);
---> player.setSubtitles();
case MediaPlayer.Event.Paused:
case MediaPlayer.Event.Stopped:
default:
break;
}
}
But when ever I tried to play the video, I got 12401-12591/? A/libc﹕ ### ABORTING: INVALID HEAP ADDRESS IN dlfree. I get this error some seconds after subtitles ar shown (Also subtitles are too small). This error is shown only when I try to show subtitles. Without subtitles video is playing without any error.
I tried to play this video on VLC application and it was able to show subtitles. I tried to create new project - got the same error. I analysed VLC android source code and it looks that they are using almost the same logic for loading subtitles (Only setting different surfaceViews for video and subtitles, but it gave me the same error). So what am I missing? What does cause player to brake and how to fix it? Maybe there is already working example of code for showing subtitles.

Categories

Resources