Android VideoView thumbnail refresh after programmatically seeking on certain devices - java

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

Related

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

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

error at WebChromeClient onProgressChanged event

I am creating a app for my blog. I used webview to load the blog site in the main activity. To make it more efficient I used a ProgressBar to do a loading animation when a url loading progress on going. Also add method when capture when another url is called, open it in the system web browser.
This is the code I have trouble with. The problem is when the program captured another url it opens a separate system browser but it keep lagging until I end the app from the Android Studio. Can somebody fix this or do there are any other option for this?
webv.setWebChromeClient(new WebChromeClient(){
#Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
if(!webv.getUrl().startsWith("https://lktechtronic.blogspot.com")){
webv.stopLoading();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(webv.getUrl())));
webv.goBack();
}else if(webv.getUrl().startsWith("https://lktechtronic.blogspot.com")){
loadinglay.setVisibility(View.VISIBLE);
if (newProgress == 100) {
loadinglay.setVisibility(View.GONE);
}
}
}
});
webv is the my WebView
loadinglay is the Layout with the ProgressBar
You may implement shouldOverrideUrlLoading and make your own WebView to load any redirect.

HTML5WebView fullscreen youtube video consumes back button click

In HTML5WebView.java (pastebin link)(source) I have:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
System.out.println("TAG - BACK PRESSED IN WEB VIEW");
return super.onKeyDown(keyCode, event);
}
And in the activity that starts the web view I have:
#Override
public void onBackPressed() {
System.out.println("TAG - BACK PRESSED IN WEB PLAYER ACTIVITY");
super.onBackPressed();
}
Now when I'm playing an embedded youtube video normally (not fullscreen), both methods are called when I press the back button. When I put the video into fullscreen mode (using the youtube player fullscreen button), none of the methods are called. My only guess is, the back button is being consumed by the web view to undo the fullscreen action (but even that doesn't work).
I am trying to get the back button to immediatly kill the web view, even if there is a video in fullscreen mode.
See the problem in action here, had to post it externally because the gif > 2MB
If I was you I would delete the embed play of youtube video's or ask google that won't be seen as abuse. Because the embed play of youtube video's can be seen as a abuse of this:
Your app violates our Device and Network Abuse policy by downloading,
monetizing, or otherwise accessing YouTube videos in violation of the
YouTube Terms of Service or YouTube API Terms of Service.
More Info: https://play.google.com/about/privacy-security/device-network-abuse/ https://www.youtube.com/static?template=terms
For example, your app contains: YouTube background play functionality
This is a violation of the YouTube Terms of Service.
That is what I got in my experience because I also made a app where people could watch some YT embed video's but after some updates the app wouldn't be update becuase I got this error that it is abuse so I am warning you that's all.

Android Speech Recognition freezes when another app is in the background

I have an app that uses google voice speech recognition. It works perfectly, but the voice capture popup freezes sometimes (see snapshot) I have narrowed down the problem to the point where as long as a commercial app called X is active in the background, the google voice popup freezes. As soon as I close app X by swiping it away, my app's speech recognition works perfectly again.
This is the code I use to launch the speech recognition popup:
#Override
protected void onResume() {
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,app.getDemoLanguageCode());
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, app.getDemoLanguageCode());
speechIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, app.getDemoLanguageCode());
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
speechIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
}
static void openGoogleASR() {
thisActivity.startActivityForResult(speechIntent, SPEECHRECON_CODE);
}
This is how the speech recognition popup looks like when it freezes while app X is active in the background:
Do you know how to properly initialize my speech recognition to make it robust against other misbehaving apps?

How to kill Android app 100% when hitting Back

I'm developing on a Galaxy S6 running Lollipop. I used Android Studio to create a ScrollView app using the template that comes with Android Studio. I only added the following Java code:
#Override
public void onBackPressed() {
Toast.makeText(this, "onBackPressed", Toast.LENGTH_SHORT).show();
super.onBackPressed();
}
#Override
protected void onPause() {
Toast.makeText(this, "onPause", Toast.LENGTH_SHORT).show();
super.onPause();
}
#Override
protected void onStop() {
Toast.makeText(this, "onStop", Toast.LENGTH_SHORT).show();
super.onStop();
}
#Override
protected void onDestroy() {
Toast.makeText(this, "onDestroy", Toast.LENGTH_SHORT).show();
super.onDestroy();
}
When I tap Back on the device, all 4 toast messages come up in the sequence that they appear in the code. However, when I view the app in Application Manager, the Force Stop button is still enabled, indicating that the process is still active. To confirm that I also downloaded a third party app to view active processes and it shows mine in the list.
Is there something that has to addes so that when hitting the Back button on the device the process will die 100% and not be on that active processes list any longer?
This is expected behavior on Android.
Android makes no guarantees as to when it will kill your app when exiting, so I'm not sure why you think it's supposed to. It's more beneficial for Android to keep your app in memory as long as possible so that its's faster to resume.
Please this code in your OnBackPressed() method:
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
That way your app will be completely closed and removed from running apps.

Categories