java.net.ProtocalException while using certain URL in VideoView android - java

I have the below list of test video links which i am am trying to set it on my VideoView. The first two works fine but the third one shows java.net.ProtocalException and I have the same problem when i user the link from my local Spring Web Application Server. How to play such link in videoView?
The list of links
1. VIDEO_SOURCE = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/SubaruOutbackOnStreetAndDirt.mp4";
2. VIDEO_SOURCE = "https://media.geeksforgeeks.org/wp-content/uploads/20201217192146/Screenrecorder-2020-12-17-19-17-36-828.mp4?_=1";
3. VIDEO_SOURCE = "https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4";
VideoView Code
if( URLUtil.isValidUrl(VIDEO_SOURCE)){
try{
videoUri = getMedia(VIDEO_SOURCE);
// Set up the media controller widget and attach it to the video view.
MediaController controller = new MediaController(_CourseContents.this);
// anchor view for the videoView
controller.setAnchorView(mVideoView);
// sets the media player to the videoView
controller.setMediaPlayer(mVideoView);
// sets the media controller to the videoView
mVideoView.setMediaController(controller);
mVideoView.setVideoURI(videoUri);
try {
HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
} catch (Exception e) {
e.printStackTrace();
}
progressBar.setVisibility(View.GONE);
}
catch(Exception e){
Toast.makeText(getApplicationContext(), "Cannot parse video source:" + e.getMessage(), Toast.LENGTH_LONG).show();
finish();
}}else {
Toast.makeText(getApplicationContext(), "Invalid video source.", Toast.LENGTH_LONG).show();
finish();
}
The Error

Related

how to send widevine data from webview to external player

i have webview where if you create a url ending in m3u8 it will open an external player,
#Override
// Force links to be opened inside WebView and not in Default Browser
// Thanks http://stackoverflow.com/a/33681975/1815624
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.endsWith(".m3u8") || url.endsWith(".ts") || url.endsWith(".mpd") || url.endsWith(".mp4"))
{
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "video/*");
intent.setPackage("com.genuine.leone");
view.getContext().startActivity(intent);
return true; // to tell the WebView that it should not load the URL because you handled it by yourself
}
catch (ActivityNotFoundException e) {
// Player is not installed, you may want to open the play store link
}
}
the problem now, m3u8 requires a widevine license to play, how to send a widevine license url to the external player
i have to research but not find anything, any idea?

Google Barcode Scanning ML kit not working for android 8.1 and below

I'm new to Android development and currently working on an app which lets the user scan the QR code using either camera or choosing a picture from Gallery using Barcode scanning kit. The app works completely fine for Android 9 (Api level 28) and above. The app works fine for all versions while scanning using camera. But for android 8 and below, I'm unable to scan any QR code if I choose a picture from gallery. I searched everywhere but didn't find any solution.
Here's the code I tried: -
mChoosePhoto = registerForActivityResult(new ActivityResultContracts.GetContent(), result -> {
InputImage image;
BarcodeScannerOptions options =
new BarcodeScannerOptions.Builder()
.setBarcodeFormats(Barcode.FORMAT_QR_CODE)
.build();
BarcodeScanner scanner = BarcodeScanning.getClient(options);
Log.v("myUri", String.valueOf(result));
try {
image = InputImage.fromFilePath(this, result);
scanner.process(image)
.addOnSuccessListener(MainActivity.this::processResult)
.addOnFailureListener(e -> {
// Task failed with an exception
Toast.makeText(MainActivity.this, "Failed to scan.", Toast.LENGTH_SHORT).show();
e.printStackTrace();
});
} catch (IOException e) {
e.printStackTrace();
}
});
And then in processResult() Method
private void processResult(List<Barcode> barcodes){
for (Barcode barcode: barcodes) {
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(100);
// Rect bounds = barcode.getBoundingBox();
// Point[] corners = barcode.getCornerPoints();
//
// String rawValue = barcode.getRawValue();
int valueType = barcode.getValueType();
switch (valueType) {
case Barcode.TYPE_WIFI:
String ssid = barcode.getWifi().getSsid();
String password = barcode.getWifi().getPassword();
int type = barcode.getWifi().getEncryptionType();
break;
case Barcode.TYPE_URL:
String title = barcode.getUrl().getTitle();
String url = barcode.getUrl().getUrl();
Toast.makeText(this, title + " " + url, Toast.LENGTH_SHORT).show();
break;
case Barcode.TYPE_TEXT:
String text = barcode.getDisplayValue();
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
}
}
}

How to launch Telegram app from my own android application?

I have an android app that should be able to open a chat in the telegram app by pressing a button.
I want to open an existing robot chat page DIRECTLY from my app. I have a valid token for my robot. How can this be achieved?
Thanks in advance.
robot name : #InfotechAvl_bot
robot token: 179284***********
//-------------
case ContentFragment.lMenuTelegram:
Intent LaunchIntent=getPackageManager().getLaunchIntentForPackage("org.telegram.messenger");
startActivity(LaunchIntent);
break;
To solve this problem you have to open robot id with this :
Intent telegram = new Intent(Intent.ACTION_VIEW , Uri.parse("https://telegram.me/InfotechAvl_bot"));
startActivity(telegram);
for Instagram and Telegram and WhatsApp you can use this methods
void getTelegram(){
try {
Intent telegramIntent = new Intent(Intent.ACTION_VIEW);
telegramIntent.setData(Uri.parse("https://telegram.me/diako099"));
startActivity(telegramIntent);
} catch (Exception e) {
// show error message
}
}
void getInstagram(){
try {
Intent instagramIntent = new Intent(Intent.ACTION_VIEW);
instagramIntent.setData(Uri.parse("https://www.instagram.com/diako_hasani99/"));
startActivity(instagramIntent);
} catch (Exception e) {
// show error message
}
}
void getWhatsApp(){
try{
String trimToNumner = "+989180074693"; //10 digit number
Intent intent = new Intent ( Intent.ACTION_VIEW );
intent.setData ( Uri.parse ( "https://wa.me/" + trimToNumner + "/?text=" + "" ) );
startActivity ( intent );
}catch (Exception e){
}
}

Optimise Way to run youtube video on android

Can we have any optimise way to run video.Below mention is my code.This code help in run the youtube video.
if (YouTubeIntents.canResolvePlayVideoIntent(activity)){
//Getting ID of YouTube video out of URL
List<NameValuePair> params = null;
try {
params = URLEncodedUtils.parse(new URI(sourceUrl), "UTF-8");
} catch (URISyntaxException e) {
e.printStackTrace();
}
String videoID = params.get(0).getValue();
Log.v(TAG, "YouTube Video ID:" + videoID);
// createPlayVideoIntentWithOptions only works for first
// video playback. Update to use stand-alone player api instead.
Intent intent = YouTubeStandalonePlayer.createVideoIntent(
activity, g.kGoogleAPIKey,
videoID, 0, true, false);
activity.startActivity(intent);
Log.i(TAG, "Video Playing in YouTube App....");
} else {
Log.v(TAG, "YouTube generic intent");
activity.startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(sourceUrl)));
Log.i(TAG, "Video Playing in whatever user selected....");
}
your question is a bit vague.. if all you want to do is play a youTube video from your app you can easily just call the yourtube intent.. and pass the url of the video as an extra. this would open youTube..
alternatively you can get access to the youTube Player api: https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/package-summary
which you will have to get an api key and do something like this:
This example looks to see if the standalone player is available to your user and if it isn't calls youtube directly as stated in the first part of my answer
if (YouTubeIntents.canResolvePlayVideoIntent(activity)){
//Getting ID of YouTube video out of URL
List<NameValuePair> params = null;
try {
params = URLEncodedUtils.parse(new URI(sourceUrl), "UTF-8");
} catch (URISyntaxException e) {
e.printStackTrace();
}
String videoID = params.get(0).getValue();
Log.v(TAG, "YouTube Video ID:" + videoID);
// createPlayVideoIntentWithOptions only works for first
// video playback. Update to use stand-alone player api instead.
Intent intent = YouTubeStandalonePlayer.createVideoIntent(
activity, g.kGoogleAPIKey,
videoID, 0, true, false);
activity.startActivity(intent);
Log.i(TAG, "Video Playing in YouTube App....");
} else {
Log.v(TAG, "YouTube generic intent");
activity.startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(sourceUrl)));
Log.i(TAG, "Video Playing in whatever user selected....");
}

upload photo to Facebook from Android

I'm trying to upload photo to Facebook from my Android App and it works fine, photo is uploaded, problem is, Facebook app doesn't open, my App simply uploads photo directly to News Feed, but without option to maybe discard it, or change text or antything, so what i would like is to open facebook post with my image attached but not posted until i click the "post"
here is my code :
Bitmap img = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher);
Request uploadRequest = Request.newUploadPhotoRequest(
Session.getActiveSession(), img, new Request.Callback() {
#Override
public void onCompleted(Response response) {
Toast.makeText(MyActivity.this,
"Photo uploaded successfully",
Toast.LENGTH_LONG).show();
}
});
uploadRequest.executeAsync();
I googled around for hours, and this facebook sdk is messed up, i can't seem to find any proper answer, if i use shareDialog facebook provides, i can't share local images, if i dont use share dialog i can't open facebook app, and i don't want to use OpenGraph stories .. Any help would be gravely appreciated.
You can post imade or text into facebook by using facebook SDK wich is explaned here
and to post an image
private void postImageToWall(String accessToken,byte[] image, String text){
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, accessToken);
//text with the image
params.putString("message",text);
// The byte array is the data of a picture.
params.putByteArray("picture", image);
try {
facebook.request("me/photos", params, "POST");
uploadSucceed = true;
} catch (FileNotFoundException fileNotFoundException) {
showToast(fileNotFoundException.getMessage());
} catch (MalformedURLException malformedURLException) {
showToast(malformedURLException.getMessage());
} catch (IOException ioException) {
showToast(ioException.getMessage());
}
}

Categories

Resources