Exoplayer Background: how to set a background for exoplayer - java

I'm development a app with a m3u8 transmission using exoplayer, and some times my transmission is offline, so a need to show a background image with it happenes, and i now find no options to solve this. The only thing with i can find is a shutter_background_color propertieswho define a color of the background player, but this not solve my problem. I need to show a bitmap image.
Please help!!!
<com.google.android.exoplayer2.ui.PlayerView
android:id="#+id/pl_aovivo"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:resize_mode="fit"
app:use_artwork="true"
app:shutter_background_color="#color/colorPrimary" />

Don't use artwork for this. The best you can do is to add an invisible ImageView inside the layout that host your PlayerView and just turn it visible when onPlayerError occurs.

If you have to set place holder image on to exo player than use below code:
<com.google.android.exoplayer2.ui.PlayerView
android:id="#+id/video_player"
android:layout_width="match_parent"
android:layout_height="#dimen/_150sdp"
android:layout_centerInParent="true"
android:visibility="visible"
app:default_artwork="#drawable/default_media_artwork"
app:use_artwork="true"
app:resize_mode="fixed_width"
app:show_buffering="when_playing" />

Related

Java Android Studio: Image View not loading from Drawable folder

I've been working on a simple java application, and wanted to add a logo as the homescreen is fairly empty. I tried using an image view, and after it didn't work I googled tutorials to make sure I was initiating it correctly. I didn't see any difference, but the actual image wouldn't load.
Xml code for image view:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src = "#drawable/logo"
android:layout_gravity="center"
android:contentDescription="#string/logo"
android:layout_below="#+id/textView"
android:layout_above="#+id/txtBody"
android:layout_alignRight="#+id/txtBody"
android:layout_alignEnd="#+id/txtBody"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:visibility="visible"
android:maxHeight="600dp"
android:maxWidth="600dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:clickable="false" />
And here's a picture of the layout preview (With an arrow pointing to the outline of where it should be, and the resource circled in the correct folder) along with a picture of the logo
Any dice if you add
android:scaleType="fitCenter"
android:adjustViewBounds="true"
Edit: also are we sure nothing is overlapping it?

Preload Picasso Image with StaggeredGridLayout

I have a StaggeredGridLayoutManager that loads 20 cards which contain images (loaded from cache, network, or storage with Picasso) in a 2 column wide grid.
Issue:
Currently, as you scroll down the list the images are loaded as the cards slide into view like this video:
https://www.youtube.com/watch?v=1xMNmMjqEbI
Desired solution:
What I would like to happen is for the images to load offscreen, so there is a seamless UX like this video:
https://www.youtube.com/watch?v=4c7ZID7yjII
These videos are from a blog post which solves this problem using LinearLayoutManager, not StaggeredGridLayoutManager. I cannot seem to figure out the equivalent solution for this issue. I'm fairly new to android development and have tried to read through the documentation but I canot seem to find anything leading to a solution.
Code:
// Setup RecyclerView
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.gridview_posts);
mRecyclerView.setHasFixedSize(true);
// Setup StaggeredGridLayoutManager
mLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(mLayoutManager);
// Set Adapter
mPostsAdapter = new PostAdapter(rootView.getContext(), posts);
mRecyclerView.setAdapter(mPostsAdapter);
// Start RestClient & get posts
restClient = new RestClient(getString(R.string.api_location));
getPosts();
Preload the images to show in a cache, so instead of loading them while you scroll the list, they're already on memory.
Picasso.with(this).load("url").fetch();
Also, remove the Picasso fadeIn animation.
Picasso.with(this).load("url").noFade().into(imageView);
Just figured out a partial solution to my own problem. Going to post it for anyone new like myself that is trying to figure this out.
The RecyclerView method setItemViewCacheSize(int size) will keep the disired amount of items in cache so you dont have flickering type loading of views.
I have not found a lookahead solution though to load a specific amount of views ahead of time.
For me it's working
Picasso.get()
.load(uploadCurrent.getImageUrl())
.placeholder(R.drawable.logoblack_loading)
.config(Bitmap.Config.RGB_565)
.into(holder.imageView);
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="#+id/id_imgItem"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/id_imgItem"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:gravity="center_horizontal"
android:textSize="18sp"/>
</RelativeLayout>

Do not show images of ImageView in real devices

I want show image in ImageView, but don't show it. I use XML code and Java code but don't show. show in simulator but in real devices don't show. tested on LG G2, HTC One X, Samsung Galaxy S3.
my xml code :
<ImageView
android:id="#+id/sms_dialog_header"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:background="#drawable/show_sms_header" />
my java code :
Dialog_Header_Img = (ImageView) findViewById(R.id.sms_dialog_header);
Dialog_Header_Img.setImageResource(R.drawable.show_sms_header);
I used to be separated from each.
Please tell me the solution
First of all you should set image in xml by code:
android:src="#drawable/show_sms_header"
not by android:background, well you can set background to color or other image but your main image you should set by android:src
If you changing something about your image, leave first line in your code that you show, and delete second, if setting image is only thing you set, then you can delete both, because you set source of image in xml.
The "src" attribute should be set to your drawable if you want it to be "centerCrop" correctly.
Check this out :
<ImageView
android:id="#+id/sms_dialog_header"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="#drawable/show_sms_header" />
Make sure that your file, called "show_sms_header", is in your drawable ( /res/drawable) directory.

How do I use this custom drawable class?

Im fairly new to android programming so im not sure on this.
Im trying to set a png as a background but the image is stretching when i use android:background="#drawable/bkgrnd" in my layout xml file
I found this custom class here http://www.anddev.org/viewtopic.php?p=27178#27178 but im not sure how to use it in my code.
Ive copied the code into its own class file and no errors are present.
How do I set the background to the drawable above using this class?
NB: I have abandoned this approach and gone with something much simpler. The answers below did give clues along with some other stackoverflow questions. Answer is below.
Please try this one it will help you.
android:src="#drawable/bkgrnd"
The result can be achieved using scale drawables instead
bkgrnd.xml (drawable xml file)
<?xml version="1.0" encoding="utf-8"?>`
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/bkgrnd"
android:scaleGravity="clip_horizontal"
android:scaleHeight="100%"
android:scaleWidth="100%"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
layout.xml
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/bkgrnd" />
In your XML, declare an ImageView like this
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#drawable/bkgrnd"
android:scaleType="fitXY"
android:layout_alignParentRight="true"
/>

Android App launches, black screen - can hear activity

I have an app that for some reason, on the latest Android SDK (4.4) launches to a black screen.
I can still hear the activity behind it (for example if I click on somewhere in the black, a button sound is clicked, so Its almost like the screen is loaded behind the black screen).
It works fine on my device which is a Nexus 4 running 4.4, it appears to be an issue on the later version (Nexus 5) devices.
It also shows the banner ad (admob) that I have, so it literally is a case that it seems to be an issue with the background image file.
//#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
mGLSurfaceView = new CCGLSurfaceView(this);
CCDirector.sharedDirector().setScreenSize(CCDirector.sharedDirector().winSize().width,
CCDirector.sharedDirector().winSize().height);
CCDirector.sharedDirector().setDeviceOrientation(CCDirector.kCCDeviceOrientationPortrait);
CCDirector.sharedDirector().getActivity().setContentView(mGLSurfaceView, createLayoutParams());
InitParam();
getAdmob();
}
Activity game xml is;
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GameActivity" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
</RelativeLayout>
width & height of the imageview is "wrap content" however the scaletype is "fitXY".
thats kind of saying 2 different things to the device.
if that image should be full screen change it's width & height to match/fill parent.
Check onCreate(), onStart() and onResume() methods in your code, you might be doing some time consuming, blocking tasks. If so, load heavy background tasks on a separate thread.
Profile your code with Traceview and dmtracedump to check what is taking more time.

Categories