Youtube player on Codenameone - java

I've been working on a codenameone app recently, and one of the app features is to play the youtube video that i chose form a list.
The list is fullfilled with a "Movie" objects, and the movie contains an embed youtube URL, for an example "https://www.youtube.com/embed/r6VO3zaBJGY".
In my form, I created WebBrowser named "player" and that's what I did :
player = new WebBrowser();
String integrationCode= "<iframe src=\"" +videoUrl+"\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen></iframe>";
player.setPage(integrationCode, null);
myForm.add(player);
it works, and I got the youtube player, but it looks aweful, and I can't put the player on full-screen.
Is there any alternative solution to play a video from a youtube URL ? or at least how can I put it on full-screen.
Thank you.

Notice that the way this looks on the simulator is different from the way it will appear on the device as youtube detects the device and adapts the rendering to it. The HTML rendering on the simulator is limited by what's available on JavaSE.
You can also customize the player appearance with a lot of optional arguments listed here: https://developers.google.com/youtube/player_parameters

Related

Showing the video of the link shared on Whatsapp for Android Java or kotlin on Whatsapp

Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, videoLink);
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
I can send the link containing the video to someone on WhatsApp, however, I want to show the image of the video to the user on WhatsApp.
Is there a way to do this in java or kotlin
as in the picture
I am not sure what you're trying to do exactly but there are two options I can think of.
Firstly, if you're looking for something like what you have in the screenshot then no coding is required.
This is usually handled by Facebook when their bot scrapes the meta tags from the page that is shared.
If you wanted to accelerate this process you can manually put the link that you want to share in Facebook's Sharing Debugger and scrape it manually so that Facebook takes note of it.
Once that is done you can share the link and it should display video information including the image, title & description.
However, if you want to share only the video image/thumbnail you can do that as follows:
grab the video ID from the URL using REGEX or by taking a substring of the URL that holds the ID.
Plug that ID in one of the following URLs to get a link to an image that you can share instead of the video.
https://i3.ytimg.com/vi/<insert-youtube-video-id-here>/default.jpg
https://i3.ytimg.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
https://i3.ytimg.com/vi/<insert-youtube-video-id-here>/sddefault.jpg
https://i3.ytimg.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg
https://i3.ytimg.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
Thanks to #asaph for his details answer on getting Youtube thumbnail here

Make an app to upload image to server in codenameone

I was using android studio for last three months but when I moved to codename one I cant get a idea as everything seems so different and I don't know where to begin. I want to choose image from gallery on button click and upload it to a server.Can you help me shai ?
It's actually much simpler than Android:
MultipartRequest request = new MultipartRequest();
request.setUrl(url);
request.addData("myFileName", fullPathToFile, "text/plain")
NetworkManager.getInstance().addToQueue(request);
Taken from the JavaDoc here: https://www.codenameone.com/javadoc/com/codename1/io/MultipartRequest.html

Facebook clipping text on Android when using an ACTION_SEND intent

I have added code to my casual game to share highest score through social networks, email, etc.
This is the text I send as defined on strings.xml resouce, for l10n:
<string name="game_sharing_score" formatted="false">
My new High Score on Gamename: %d\n
You can download Gamename from here:\n
https://play.google.com/store/apps/details?id=gamepackage
</string>
Please, note that Gamename and gamepackage are not the actual ones that I am using.
The code for sharing is the following one:
String shareScoreMsg = String.format(context.getString(R.string.game_sharing_score), highestScore);
Intent shareScoreInt = new Intent(Intent.ACTION_SEND);
shareScoreInt.setType("text/plain");
shareScoreInt.putExtra(Intent.EXTRA_TEXT, shareScoreMsg);
game.startActivity(Intent.createChooser(shareScoreInt, context.getString(R.string.game_sharing_score_title)));
game is an Activity, context is an Application context, game_sharing_score_title is the title of the activity "Share your score". Anyway there is no problem with the code it self, it is working fine for sharing through Google+, WhatsUp or Twitter, but when the user selects to share through FaceBook, the text is clipped and it publish only the last link, with the information and one icon image that FB gathers from Google Play, ignoring all the text before the link.
It is pretty clear that the problem is just with Facebook, no with the code or the string.
What I would like to find is some kind of workaround, if exists, to avoid these FB problems. To be honest, I do not like Facebook, but it is a social network with millions of people and I cannot simply ignore it on my game.
Thanks a lot in advance,
Create Facebook app on your account
After that, you get the App id.
Access all methods from Facebook API.

Android: custom Facebook integration

I need some advice for this matter...
I used the facebook android sdk to create an integration with facebook from my application...I followed this tutorial:
http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/
I would need to implement authentication in one activity and the function postToWall in another.... after authentication i want to send post simply by pressing a button but in other activity, different from that where i do authentication.
is it possible? or with the SDK I'm forced to do everything together in the same activity?
thanks in advance
Yes it is possible. You will get a access token which you can send to the next activity. Use getAccessToken() and setAccessToken().
Here is an example that even saves the needed data: Contact-Picture-Sync
you need to install an extension, similar to the core Android SDK, but no, here is what you need to do:
1.) go to github.com/facebook/facebook-android-sdk
2.) download the facebook directory ONLY! The other directories are only examples.
3.) Put the files from the src (you can copy the drawables too, if you want to) in the package, you are currently working with
4.) You are good to go, you can use the facebook "SDK"
see also this example https://github.com/facebook/facebook-android-sdk/tree/master/examples/Hackbook download it , it is working example provided by facebook
just to provide an alternative answer, there's other ways of implementing sharing on Android.
It allows for more sharing options (like Twitter, QR-Barcodes, blogging and whatnot) without having to deal with the facebook android sdk.
What you would use is a "share" intent, like so:
String title = "My thing"; // used if you share through email or channels that require a headline for the content, always include this or some apps might not parse the content right
String wallPost = "Hey - check out this stuff: http://link.com "; // the content of your wallpost
String shareVia = "Share this stuff via"; // the headline for your chooser, where the phones avaliable sharing mechanisms are offered.
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, wallPost);
startActivity(Intent.createChooser(shareIntent, shareVia));
This is by far the preferred solution on Android if you're looking for simple sharing, as it makes your app future-compatible with new services. And more lean and flexible for the user too, as there's little to no friction from hitting the share button to posting content.
It can also be seen in this blog post: http://android-developers.blogspot.com/2012/02/share-with-intents.html
I hope you can use this for your project.

Blackberry: how to embed youtube video inside an application

I need to play a youtube video from my bb application. Does anyone know how to do that? Can I have a youtube video player directly inside my app or can I at least have a link to open youtube video in the browser?
What you want to do is get the rtsp streaming URL for the video. When I browse to YouTube on a BlackBerry with the native browser, it serves a page with links to this format. If you know exactly which video to play at build-time, great. If it's going to be picked by your users, you'll have to figure that out.
Then, with that URL, you can create a Player like this:
Player p = Manager.createPlayer("rtsp://SOME_YOUTUBE_VIDEO_ID_HERE/video.3gp");
p.realize();
VideoControl vc = (VideoControl)p.getControl("javax.microedition.media.control.VideoControl");
Field f = (Field)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field" );
The Field f can be added to your screen. And you can start the video with
p.start();
References:
http://docs.blackberry.com/en/developers/deliverables/11942/Create_BB_app_that_plays_streaming_media_739691_11.jsp
http://docs.blackberry.com/en/developers/deliverables/11942/Create_BB_app_that_plays_a_video_in_a_UI_field_739692_11.jsp

Categories

Resources