nativescript-videoplayer icon indicating copy to clipboard operation
nativescript-videoplayer copied to clipboard

Automatic height

Open 3rror404 opened this issue 6 years ago • 2 comments

Setting fixed dimensions for the video player causes all sorts of layout issues when dealing with a multitude of screen sizes.

I would like the player to have a fluid width based on the parent element and a height that automatically adjusts so that the video fills the player - avoiding pillar/letter boxing.

Is there any way that the video player can automatically choose the appropriate height based on the aspect ratio of the loaded media?

3rror404 avatar Sep 13 '18 14:09 3rror404

I would like to do the same thing. Did you found any solution?

JonasJW avatar Nov 10 '18 16:11 JonasJW

I got something like with the nativescript Exoplayer. It also should work with this player. You have to set the height at runtime depending on the available width and aspecting the video resolution ratio.

@Component({
    moduleId: module.id,
    selector: "MyComponent",
    templateUrl: "./my.component.html",
})
export class MyComponent implements OnChanges {
    public videoHeight: number;
    public video: Video; // Video contains at least two properties width and height (and videoUrl…)

    public ngOnChanges(changes: SimpleChanges): void {
        const ratio: number = this.video.height / this.video.width;

        this.videoHeight = platformModule.screen.mainScreen.widthDIPs * ratio; //here you also could use the width of any container element; i use the total width of the screen
    }
}
<StackLayout orientation="vertical" [row]="row">
    <Label class="h3" [text]="video?.name"></Label>
    <Exoplayer autoplay="true" controls="false" [height]="videoHeight" loop="true" [src]="video?.uri">
    </Exoplayer>
</StackLayout>

raman-nbg avatar Nov 11 '18 23:11 raman-nbg