How to solve MediaPlayer Error "Can't play this video" - java

I had a problem with my videoview.
When I try play video from specific URL at my API-27 emulator Android show me message dialog
Can't play this video
That's it what I get in Logcat
source returned error -1010, 0 retries left
initFromDataSource, source has no track!
Failed to init from data source!
MediaPlayerNative: error (1, -2147483648)
MediaPlayer: Error (1,-2147483648)
That's my code where I use my videoview
mVideoView = findViewById(R.id.videoView);
mMediaController = new MediaController(this);
mVideoView.setVideoPath("https://clips.vorwaerts-gmbh.de/VfE_html5.mp4");
mVideoView.requestFocus();
initListeners();
initListeners method
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mVideoView.setMediaController(mMediaController);
mVideoView.setBackground(null);
mMediaController.setAnchorView(mVideoView);
mMediaController.show();
mVideoView.start();
}
});
mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
mVideoView.setBackground(getDrawable(R.drawable.webinar_photo_preview));
}
});
I test my videoview feature at api23, api24 and everything sounds good.
Can somebody tell me what I'm doing wrong?
EDITED: Now I found that the error also appears on api24

Problem was in VideoView, setVideoPath set videos only with little file size (1 - 2 MB) and if it size is bigger MediaPlayer crashes with MEDIA_ERROR_SYSTEM (-2147483648) - (low-level system error), read in documentation . That why I start using exoPlayer.

Its look like your code is working fine and maybe the problem is that you are not using cookies that are send to browser at the time of request.
In simple terms this video is not for direct access via code.
If you still wants to try the steps below.
Make http request to link (https://clips.vorwaerts-gmbh.de/VfE_html5.mp4) and store the received cookies.
Use the received cookies with your next request when you want to play the video.
Note - If you want to use cookies to play video it can be done via ExoPlayer(https://github.com/google/ExoPlayer).

Related

ExoPlayer: play a video with chuncks

Through WebSocket, I'm getting chunks of a video file that I want it to play immediately in ExoPlayer. In fact, I'm trying to implement video file streaming which works very well on the web page with MediaSource and appendBuffer which update the player with a new chunk. So I want something similar to that.
Here is where I'm receiving chunks
#Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
// here is chunk
// bytes.hex()
// I want to update exoplayer or to start exoplayer in case it is the first chunk
}
I've been looking for how to do it but I didn't find a solution. So I really need help

This code work only for video, not for streaming

My problem is reading videos and streaming on the net. If I know the location of a video file and I want to read it I just do:
String Url = "https://www.w3schools.com/html/mov_bbb.mp4";
VideoView videoView;
protected void onCreate (Bundle savedInstanceState) {
...
videoView = (VideoView) findViewById (R.id.loadVideo);
videoView.setVideoURI (Uri.parse (this.Url));
videoView.start ();
But if the video is a stream, for example sent from my computer, I know the address (example: 127.0.0.1:8080 , yeah is random example i know this is localhost and can't work in localhost, but i can't use the real address of video sorry) and I can play from windows via Vlc quietly, the video is not played, the code ends up "catch", then the same syntax can not be used for video streaming via http address.
I looked everywhere on the internet, but I did not find any working solution and many plugins seen are now obsolete and / or unusable with android studio. I'm not a professional Android programmer, but I've been asked to do it, do you know how I can do it?
I forgot: the intention is to create a live stream

Android VideoView thumbnail refresh after programmatically seeking on certain devices

In my application I sometimes have to programatically skip the video to a certain position according to user input.
The problem I'm having is that when the video is paused and I seek to a specified value the thumbnail does not refresh (the videoview still displays the image where it was initially paused).
This however happens only on devices such as the Galaxy S4, the HTC One or the Nexus 10 (maybe something related to the API or the resolution, not exactly sure), while it works as expected on Galaxy S2, Nexus 7 and other lower-end devices.
I've tried a "hacky" approach such as starting and pausing the video with no success (the image in the videoview does not update).
I'm hoping that someone with a bit more experience can tell me if there is any way to refresh the video's thumbnail programmatically.
You can use the SeekOnCompletedListener of the underlaying MediaPlayer of the VideoView and pause right after it seeked.
void Seek(int position) {
VideoView1.start();
VideoView1.seekTo(position);
}
VideoView1.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
#Override
public void onSeekComplete(MediaPlayer mp) {
VideoView1.pause();
}
});
}
});

How to read NFC Tag and call Webservice in Android

I'm now developing an android application with the NFC concept . In that application I need to pick my application if I swipe the NFC card and if I select my application my application must start calling webservice.
when it comes to my problem, If suppose my app crashed ,when I swipe the card next time ,the option to choose the application doesn't open .Instead,my application directly launched and couldn't call the webservice data.
On the whole.I'm getting last page when it crashed .But I need to open as fresh
I came to know that I need to make changes in OnResume() and OnNewIntent().
I used ,
In OnResume()
super.onResume();
mNfcAdapter.enableForegroundDispatch(this, nfcPendingIntent, mNdefExchangeFilters, null);
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
NdefMessage[] msgs = getNdefMessages(getIntent());
byte[] payload = msgs[0].getRecords()[0].getPayload();
//Toast.makeText(this, new String(payload), Toast.LENGTH_LONG).show();
Student=new String(payload);
if(Student.equals(rakesh)
{
new Webservice.execute(""); // Calling SOAP Webservice
}
But,I can't find any changes with my problem .and one more thing that the problem will be resolve after I just open and close an another NFC project
Please help.
Yeah ! I got the solution .I forget a simple thing that I left calling onStop() method and my problem was,when my application stops(when Crashed).It runs in background as the previous activity.
I just tried the following,
public void onStop()
{
super.onStop();
this.finish();
}
This may be helpful to others.
Thanks..

Android: Play RTSP video from URL

I'm trying to play an RTSP url in my android app, using the following code:
String url = "rtsp://mobilestr1.livestream.com/livestreamiphone/nyc";
Uri uri = Uri.parse(url);
System.out.println("URL="+url);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
However an alert dialog pops up after a few seconds saying "Unable to play video".
I have tried several RTSP urls and none of them work. What am I doing wrong?
Thanks
That stream is h264 MPEG-4 AVC Part 10. Which doesnt work on most android devices.
This page has a list of what does work. But essentially you need an MPEG-4 Baseline stream.
http://developer.android.com/guide/appendix/media-formats.html#recommendations
If you open the stream in VLC and then :
Window > Media Information > Codec Details you can verify this info as well
Try the below code. It works for me. Don't forget to add internet permission in your manifest.
private void rtspStream(String rtspUrl) {
mVideoView.setVideoURI(Uri.parse(rtspUrl));
mVideoView.requestFocus();
mVideoView.start();
}

Categories