[Obj-C] How to make a videoTrack fill its UIView?

1,229 views
Skip to first unread message

Iñaki Baz Castillo

unread,
Jun 25, 2015, 11:52:02 AM6/25/15
to discuss...@googlegroups.com
Hi,

Let's assume I've a UIView with size 400px width x 300px height, and I
want to render a RTCVideoTrack of 600px width x 300px height in a way
that the video may be clipped to fill the UIView’s bounds.

I don't know how to make it work. In fact the videoTrack is always
stretched (deformed).

Basically I want the same behavior as the CSS "object-fit: cover",
which is shown here:

http://jsbin.com/yaheka/edit?html,css,output

Is there something I can do to mimic that behavior?


Swift code:
----------------------------
var view: RTCEAGLVideoView

view.frame = CGRectMake(
CGFloat(left),
CGFloat(top),
CGFloat(400),
CGFloat(300)
)

rtcVideoTrack.addRenderer(view);

// TODO: Make the video fill/cover the view.
// This does not work:
view.contentMode = UIViewContentMode.ScaleAspectFill
------------------------------




--
Iñaki Baz Castillo
<i...@aliax.net>

Iñaki Baz Castillo

unread,
Jun 25, 2015, 12:21:15 PM6/25/15
to discuss...@googlegroups.com
2015-06-25 17:51 GMT+02:00 Iñaki Baz Castillo <i...@aliax.net>:
>
> Swift code:
> ----------------------------
> var view: RTCEAGLVideoView
>
> view.frame = CGRectMake(
> CGFloat(left),
> CGFloat(top),
> CGFloat(400),
> CGFloat(300)
> )
>
> rtcVideoTrack.addRenderer(view);
>
> // TODO: Make the video fill/cover the view.
> // This does not work:
> view.contentMode = UIViewContentMode.ScaleAspectFill
> ------------------------------


I need something equivalent to what it can be done in the Android version:

------------------------
new VideoRenderer(VideoRendererGui.create(x, y, videoSizeAsPercentage,
videoSizeAsPercentage,

VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, true)));

Iñaki Baz Castillo

unread,
Jun 25, 2015, 7:29:15 PM6/25/15
to discuss...@googlegroups.com
I've finally implemented the desired behavior by using a UIView within another UIView.

Erid Bardhaj

unread,
Aug 22, 2015, 3:36:20 AM8/22/15
to discuss-webrtc
I used the same approach as you did, the frame from iOS Devices and Web were rendering great, but when tried a specific Android device, the view went stretched :/

Parthi Kannan

unread,
Mar 17, 2016, 11:27:50 AM3/17/16
to discuss-webrtc
Can you please explain a little more on how you made this work with some example code if possible

Iñaki Baz Castillo

unread,
Mar 17, 2016, 1:29:07 PM3/17/16
to discuss...@googlegroups.com

Tiago Bernardo

unread,
Sep 7, 2016, 11:48:56 AM9/7/16
to discuss-webrtc
Need some help, im new to swift, can you give me some simple tips how to do it?

 I have one rtcvideoview and with one rtcvideotrack, but the image is always blurred. I want it to fit to all devices sizes with constraints, but I don' t know how to do it

Some help?
Reply all
Reply to author
Forward
0 new messages