Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Android playerView not visible in my activity


I got an activity that display the content of a WP article : a title, a content, an image, and a video.
Image and video are url (string). I want to Instantiate a JWPlayerView programmatically, so I got no JWPlayerView tag in my xml, but i want to display it on a linearlayout.

PlayerConfig playerConfig = new PlayerConfig.Builder()
.file(urlVideo)
.build();

JWPlayerView playerView = new JWPlayerView(context, playerConfig);
linearLayout.addView(playerView);

When I launch my app, I see briefly a loading sign where the video is supposed to be played, but it quickly disappear and nothing happend after : I can't see the player.
If i add this line : playerView.setMinimumHeight(300); it works, but when I switch to fullscreen mode (when I rotate screen or click on fullscreen button), the video switch in full screen mode (everything else dissapear) but it only occuped the height define in setMinimumHeight and the remaining is fill with white background.
Is there a way to better define a specific height, and switch to full screen when needed?
Here's my onConfigurationChanged() method to switch to fullScreen :

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.i("orientation", String.valueOf(newConfig.orientation));
Log.i("getFullScreen", String.valueOf(playerView.getFullscreen()));
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
if(playerView.getFullscreen()) {
playerView.setFullscreen(false, true);
}
} else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
if(!playerView.getFullscreen()) {
playerView.setFullscreen(true, true);
}
}
}

5 Community Answers

George

JW Player Support Agent  
1 rated :

Hi,

If you’re adding the JWPlayerView programmatically to your ViewGroup, don’t forget to create the appropriate LayoutParams and set it on the JWPlayerView.

Also, keep in mind the player will hide all views when it goes fullscreen, so when returning from fullscreen you’ll want to make sure your set the visibility to VISIBLE for the views that are hidden. You’ll want to use the OnFullscreenListener to manage that.

RomainC

User  
0 rated :

Thanks for you reply.
I try to do this, but not sure I did it well... :

playerView.setLayoutParams(linearLayout.getLayoutParams());
ViewGroup.LayoutParams params = new JWPlayerView.LayoutParams(playerView.getLayoutParams().MATCH_PARENT, 400);
playerView.setLayoutParams(params);
linearLayout.addView(playerView);

It works, my video take the width of the parent (linearlayout) and 400 in height, but when I rotate my phone, it's correctly switch in fullScreenmode, but I think the height is still blocked to 400.
PORTRAIT: https://goo.gl/JVc5zi
LANDSCAPE: https://goo.gl/vBfEVx

The only thing I do when I rotate is playerView.setFullscreen(true, true); in my onConfigurationChanged() methode (posted before)

George

JW Player Support Agent  
0 rated :

For me to reproduce this issue reliably I will need this information about your application:

Device’s Android Version:
JW Player SDK for Android version number:
Device make and model where you are experiencing this issue:
Provide step by step instructions on how to reproduce your issue:
JW Player Demo Application Source Code that is also experiencing the issue:

As the last field suggests, please replicate this issue using the JW Player Demo Application and send us a link to a zipped version of the entire Android Studio Project for testing which can be found here:
https://github.com/jwplayer/jwplayer-sdk-android-demo

RomainC

User  
0 rated :

Device’s Android Version:
7.1.1

JW Player SDK for Android version number:
compile 'com.longtailvideo.jwplayer:jwplayer-core:+'
compile 'com.longtailvideo.jwplayer:jwplayer-common:+'

Device make and model where you are experiencing this issue:
Nexus 5X

Provide step by step instructions on how to reproduce your issue:
I get an article from a WP API using http request, and I load title, content,AND image and video if available (optional, not every article have image & video).
I used the code linked in previous post for the moment. The main problem is the height of the video (0 by default) and when I fix it and rotate device to go on fullscreen mode, the video is fix with the same height.

JW Player Demo Application Source Code that is also experiencing the issue:
I will try to modify and reproduce the bug in the demo. The main diff I see are:

-there is a <com.longtailvideo.jwplayer.JWPlayerView> in the xml file, and not in mine because I want to add the JWPlayerView programmatically (the video is not always in the same position in an article)

-I don't see any setLayoutParams in the JWPlayerViewExemple java file, and I can't understand where the height is define (except in the xml file)

Have a good week end

George

JW Player Support Agent  
0 rated :

Hi,

I’m missing the following:
JW Player Demo Application Source Code that is also experiencing the issue:

As the last field suggests, please replicate this issue using the JW Player Demo Application and send us a link to a zipped version of the entire Android Studio Project for testing which can be found here:
https://github.com/jwplayer/jwplayer-sdk-android-demo

This question has received the maximum number of answers.