How can I scale video in ExoPlayer-V2 - Play Video In Full Screen - aspect-ratio

I am playing video from URL on Exoplayer, it stretching the video on resizing/on using resize_mode as I have mentioned in layout file using this I am not able to maintain the aspect ratio of video.
I want to do scale type CENTER_CROP like we do in TextureSurface as mentioned in image2 but I am getting output as image1
I have tried following example
Exoplayer Demo Example
My Output (Img 1) and Expected Output (Img 2)
exoplayer layout code
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="#+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:resize_mode="fill" />
With this line app:resize_mode="fill" it fit the video in screen but stretch vertically,
So how can I solve this .

Following two lines helped me to play video in full-screen mode.
Using app:resize_mode in layout file this somehow help but it stretches the video as mentioned in the question picture.
<com.google.android.exoplayer2.ui.PlayerView
android:layout_width="match_parent"
app:resize_mode="...."
android:layout_height="match_parent" />
Try changing AspectRatioFrameLayout to FILL,FIT,ZOOM... as per yout requirement, changing below line worked for me.
exoVideoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
Bellow line will ensure that aspect ratio is correctly maintained even for 4:3 videos.
exoPlayer.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
Also you can try changing VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING in exoplayer

To maintain center crop in exo player below code worked for me:
Java code:
playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
or you can use from xml:
<com.google.android.exoplayer2.ui.PlayerView
android:id="#+id/playerView"
android:layout_width="match_parent"
app:resize_mode="zoom"
android:layout_height="match_parent" />

Following are the Resize Mode options to play around with
app:resize_mode="fixed_width"
app:resize_mode="fixed_height"
app:resize_mode="fill"
app:resize_mode="fit"
app:resize_mode="zoom"
You can try each one to see its affect on your container.

My issue was solved using below lines:
playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
exoPlayer.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);

Kotlin :
AndroidView(
modifier = Modifier.fillMaxSize().fillMaxHeight().fillMaxWidth(),
factory = {
StyledPlayerView(context).apply {
this.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL
}
})

Related

Browser picks the wrong srcset image

I'm trying to implement srcset this way
<img class="i-product-image-big"
srcset="http://dev.test:8000/uploads/thumbnail-80/1602202734The_Reptile_Room_by_Daniel_Handler.webp 80w,
http://dev.test:8000/uploads/thumbnail-160/1602202734The_Reptile_Room_by_Daniel_Handler.webp 160w,
http://dev.test:8000/uploads/thumbnail-320/1602202734The_Reptile_Room_by_Daniel_Handler.webp 320w,
http://dev.test:8000/uploads/thumbnail-640/1602202734The_Reptile_Room_by_Daniel_Handler.webp 640w,
http://dev.test:8000/uploads/thumbnail-960/1602202734The_Reptile_Room_by_Daniel_Handler.webp 960w,"
src="http://dev.test:8000/uploads/thumbnail-160/1602202734The_Reptile_Room_by_Daniel_Handler.webp"
alt="The Reptile Room by Daniel Handler">
I edited the code by adding sizes like this
<img class="i-product-image sidebar_image" loading="lazy"
sizes=" (min-width 200px) 320px, (min-width 576px) 80px, (min-width 768px) 160px, 100vw"
srcset="http://dev.test:8000/uploads/thumbnail-960/1586515257Little_History_of_the_World.webp 960w
..........
I open the website in private window in responsive mode first to be sure that the browser didn't load the larger version but the problem is I find out that the browser picks the wrong version (size) of the image. Here it should pick the 320px (it's 322px including 1px border from each side and the image itself is 320px) version of the image but it picks the 640px version of the image. Why is that and how to fix it without using the picture tag?
I reduces the size of the image in css but still loading 640xp version
I reversed sizes like this
sizes=" (max-width 575px) 320px, (max-width 767px) 80px, (min-width 768px) 160px, 100vw"
But that didn't work either
OK, did some tests here (created some filler images to debug). Found what's causing your issue. Not being able to see your full HTML code, I could get the 320-pixel-width image to show in a bare-bones, hand-coded HTML page. When I add the standard viewport tag: <meta name="viewport" content="width=device-width, initial-scale=1">, the 640-pixel-width image will display again, due to viewport scaling. If I were to post your code in a snippet here on SE, the same thing would happen.
Additionally, if I replace the 320_Image.png 320w, with 320_Image.png 2x, and 640_Image.png 1x,, the 320-pixel image will show, but the display will be broken when viewed in the desktop.
If all you’re trying to do is serve an image size that’s based on the viewport width, you’d be best served using 160_Image.png 160w, while for resolution switching, use this: 160_Image.png 1x. A comprehensive resource on responsive images on MDN describes this more fully. And, based on your preference not to use the <picture> element, this article is a good resource. The author recommends not using the <picture> element when all you want is to serve the appropriate image based on the users' device.
For a quick demo, I’ve modified the code a bit, and am using dummy images to show (not including fillers for all the images in the code). If viewed in desktop, the images will switch sizes based on viewport width. For mobile, they will switch based on device width. I only added the CSS to set the image to full-width debugging, but the images with switch without this code.
img {
max-width: 100%;
width: 100%;
}
<img class="i-product-image-big" srcset="80_Image.png 80w,
160_Image.png 160w,
https://i.stack.imgur.com/JkhiN.png 320w,
https://i.stack.imgur.com/Lwddt.png 640w,
https://i.stack.imgur.com/8Z9jL.jpg 960w" sizes="(max-width: 575px) 320px, (max-width: 767px) 640px, (min-width: 768px) 960px, 100vw" src="https://i.stack.imgur.com/8Z9jL.jpg" alt="Test Responsive Image">

Responsive srcset images by media query?

Have I misunderstood the img srcset tag if I say that I'd like to specify to the browser what image to show when the screen is max-size: 599px (mobile) and when it's above that?
<img
srcset="
small.jpg 600w,
big.jpg 2000w"
sizes="
(max-width: 599px) 600w,
2000w"
src="big.jpg" alt="Some text" />
This code doesn't behave at all how I'd expect it to. I'd like the browser to show the small image when it's a mobile screen, and show the large one for every other device resolution. Is there no way to do this simply? So confusing.
I've read articles on SitePoint, Smashing Mag, etc, and none of them explains it simply as above. They go into image widths, viewports, ratios, etc. All I need is to specify in a media-query screen resolution style which image to show at which resolution.
Many thanks.

Hide wowza overlay after an interval of time

I am using Wowza Media Streams for a live streaming in my project. I am using overlay on video. My question is, that I want to hide displaying overlay after an interval of time. Please guide me is there any way to do this. My code is for using overlay is
wowzaImage = new OverlayImage(basePath+"logo_14.png",100);
mainImage.addOverlayImage(wowzaImage,srcWidth-wowzaImage.GetWidth(1.0),0);
This is being used to display overlay. To Hide this overlay after fix time, I tried this
mainImage.addOverlayImage(null,srcWidth-wowzaImage.GetWidth(1.0),0);
But this didn't work. Also tried
wowzaImage = new OverlayImage(basePath+"logo_14.png",0);
mainImage.addOverlayImage(wowzaImage,srcWidth-wowzaImage.GetWidth(1.0),0);
But it still shows overlay there.
Please help, Thanks
If you are looking at the example here you can find a couple of ways to accomplish this (depending on how you've set it up). You can leverage the add fading step convenience function as follows:
mainImage.addFadingStep([start-value],[end-value],[number-of-frames]);
Otherwise you can fade the image itself away on each frame (see onBeforeScaleFrame event handler) similar to the way you were suggesting in your question:
OverlayImage img = new OverlayImage([resource], opacity);
mainImage.addOverlayImage(img,xpos, ypos);
For the latter you will want to be sure it is being referenced correctly and that the positioning holds true.
Thanks,
Matt

QT background image not showing using stylesheets

I'm using QT for C++ and I set this stylesheet code:
QFrame {
background-image: url(img.png);
}
The image doesn't show! It's located in the debug directory inside the QT directory. Why doesn't it show?
edit:
doesn't even work with the resource system
edit 2:
It shows now, but only if I use QWidget instead of QFrame. The only problem is that the image repeats when I resize the window. How do I make it stretch normally instead?
edit 3:
OK, I used JUST border-image now and it stretches. However, it's glitchy(if you move a bit fast you can go over the original image), and very slow(if you're not resizing slowly enough, it will stutter and until it manages to stretch there will be a white gap). Can't I get it to resize normally? =/
Using this stylesheet code:
QWidget {
border-image: url(:/images/img.png);
}
edit 4:
Well if I'm already at it.. what about clickable areas in images? Is that possible?
edit 5:
come on..anyone? this is important
Add your image to resources (.qrc file) of your application.
Then refer to it in your stylesheet:
QFrame
{
background-image: url(:/Style/img.png);
}
I think you should use Qt Resource System instead of having an image inside the folder. Images can also be speicified without the url function.

gradients using only html and css and javascript?

Is there a way to do gradients in css/html/javascript only that will work across all the major browsers? (MS IE 5+, Firefox, Opera, Safari)?
Edit: I would like to do this for backgrounds (header, main panel, side panels). Also, would like to have vertical line gradients as well.
Edit: after reading the responses, let's open this up to Javascript solutions as well, since HTML/CSS by itself makes it tougher to achieve.
I've done this before as a gimmick, using javascript like:
var parent = document.getElementByID('foo');
for(var i=0; i< count; i++) {
var div = document.createElement('div');
div.style.position = 'absolute';
div.style.width='100%';
div.style.height = 1/count+"%";
div.style.top = i/count+"%";
div.style.zIndex = -1;
parent.appendChild(div);
}
If your requirement is just to have a gradient, you really should use a gradient image set as background-image in css. In my case, I was animating the colors and position of the gradient as well. I can't vouch for now cross-browser it is (for starters, make sure the parent has some position applied, otherwise it won't be a position-container for the absolute positioning.
I'm unclear on the implementation details you are seeking (such as background, or just a border along the side of the window, etc); however, it's possible albeit a little tedious.
One example that comes to mind would be to have n-block level elements, such as divs, and then give them each a small height (a couple of pixels, for example) and then gradually change the background color of each subsequent element.
I use the gradient CSS code generator by colorzilla: http://www.colorzilla.com/gradient-editor/
It has polyfills for IE - but not sure how far back it goes.
I think the short answer is no.
You can create something that looks like a gradient using only css, but to then use it like an image background... I think that is pushing it a bit.
EDIT (feeling silly)
I found the solution: http://en.wikipedia.org/wiki/JPEG
There are lots of ways to create a gradient now.
1. You can create image for it.
2. Use CSS3 Gradient, it can be linear, radial and repeating.
Syntax for linear :
linear-gradient: ([angle | to ] ,[ [color-stop], [color-stop]+);
Syntax for radial :
linear-gradient: ([angle | to ] ,[ [color-stop], [color-stop]+);
For IE6 to IE 9 we can use the filter property or you can also use CSS3Pie.
Following are some referances that will help:
Mozilla MDN
CSS3File