codename one mediaplayer not working on android device - java

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

Related

Why code for capturing video is not working in one plus?

I used video capturing code using built-in camera in an application, but it reporting issues some of android phones like OnePlus phones. in other phones it works perfectly, can anyone help me to solve this issue, i tried many times but it didn't work, I'm sharing my code below..
Acutually it is shows only in device like one plus, I try to use built-in cam for to recording video, in my project, After we click button for to record video, it will redirected to the built-in cam in the device, in other devices it's working perfectly. but in one plus version11 , after we click the button for to record video it will not redirected to built-in cam, it is just stuck with the same page.. this is the issue
private void captureVideo() {
Intent VideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (VideoIntent.resolveActivity(getPackageManager()) != null) {
VideoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
VideoIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
VideoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 3);
VideoIntent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION,true);
startActivityForResult(VideoIntent, VIDEO_REQUEST);
}
}

Parsing logcat output on android phone [duplicate]

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

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.

Share an image and tag some people in a Android App to google plus from inside the code

I'm creating an Android App that shares an image or a text in your google plus profile. I need to tag some people from inside the code with the function -> .setRecipients(recipients). I succeeded to share an image in google plus or share an text tagging some people from inside the code. But i couldn't do both of them, i tryed to share an image and tag people from inside the code, but when i share the image with function addStream(myUri), the function setRecipients(recipients) stop working. If i comment the addStream(), the setRecipients() works fine but don't shares the image. I tryed to change the setType to "video/, image/" or "image/jpeg", but nothing. Any suggestions?
ArrayList<Person> recipients = new ArrayList<>();
recipients.add(PlusShare.createPerson("106189723444098348646","Larry Page"));
recipients.add(PlusShare.createPerson("109813896768294978296","Sergey Brin"));
Uri myUri = Uri.parse("content://media/external/images/media/10222");
Intent shareIntent = new PlusShare.Builder(this)
.setType("text/plain")
.setText("Sharing in google plus!")
.setRecipients(recipients)
//.addStream(myUri)
.getIntent();
startActivityForResult(shareIntent, 0);

Categories

Resources