3

When I run my app I'm having these issues.

  • A black screen flashes for 2 secs and then displays the actual intent of my app.
  • The video gets started and when I scroll up/down, the VideoView turns white and continues playing. Not able to see the video but plays in background.
  • After playing is done, for few seconds I'm getting this "Can't play this video" dialog.

This is the excerpt from my Adapter Code:

public class MessageAdapter extends ArrayAdapter<Message> {
    private static class ViewHolder {
        TextView authorTextView, timeStamp, messageTitle, messageTextView;
        VideoView videoView;
        ImageView photoImageView;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        // Gets the message that we are displaying at a position
        Message message = getItem(position);

        ...

        boolean isPhoto = message.getPhotoUrl() != null;
        boolean isVideo = message.getVideoUrl() != null;

        if (isPhoto) {
            // Photo Present

        } else if (isVideo) {
            // Video present
            Log.d(TAG, "Video present !");
            viewHolder.messageTextView.setVisibility(View.GONE);
            viewHolder.photoImageView.setVisibility(View.GONE);
            viewHolder.timeStamp.setVisibility(View.VISIBLE);
            viewHolder.videoView.setVisibility(View.VISIBLE);
            viewHolder.videoView.setVideoPath(message.getVideoUrl());
            viewHolder.videoView.start();
            Log.d(TAG, "Video URL : "+message.getVideoUrl());
        } else {
            // Photo and video both absent
        }
        return convertView;
    }
}

I'm getting this on LogCat:

After displaying the Logged info there is a following warning as shown below

D: Video present !
D: Video URL : https://firebasestorage.googleapis.com/v0/b/xxx.appspot.com/o/photos%2Fvideo%3A34334?alt=media&token=05xf6c2f-6abc-4ab9-b696-32153fa3d0aa
W: Couldn't open https://firebasestorage.googleapis.com/v0/b/xxx.appspot.com/o/photos%2Fvideo%3A34334?alt=media&token=05cf6c2f-6abc-4ab9-b696-32153fa3d0aa: java.io.FileNotFoundException: No content provider: https://firebasestorage.googleapis.com/v0/b/xxx.appspot.com/o/photos%2Fvideo%3A34334?alt=media&token=05cx6c2f-6abc-4ab9-b696-32153fa3d0aa
I: proxyName: 0.0.0.0 0
W: finishComposingText on inactive InputConnection
D: getMetadata
I: proxyName: 0.0.0.0 0
W: info/warning (703, 0)
I: proxyName: 0.0.0.0 0
V: Inactivity, disconnecting from the service
I: proxyName: 0.0.0.0 0
I: proxyName: 0.0.0.0 0
E: error (1, -2147483648)

This is my VideoView Layout:

<VideoView 
    android:id = "@+id/admin_video_view"
    android:layout_width = "300dp"
    android:layout_height = "200dp"
    android:layout_weight = "1"
    android:layout_marginLeft = "10dp"
    android:paddingTop = "5dp"
    android:scaleType = "centerCrop" />
coderpc
  • 4,119
  • 6
  • 51
  • 93
  • Where is a Firebase? Have you started this app in other devices or emulators? – CoolMind Jun 09 '17 at 09:08
  • @CoolMind That's in my MainActivity. Updated my question with that just now. Please see above. – coderpc Jun 09 '17 at 14:41
  • Now that I've downloaded locally from Firebase Storage to my Mobile Storage. Got a hint from [here](https://stackoverflow.com/a/42057701/7004388). Now the question is, where do i set the path of the Video in `MessageAdapter` ? or `MainActivity` ? Can you please guide me. @CoolMind – coderpc Jun 09 '17 at 20:19
  • 1
    Is it working good if you try from a local resource like a `.mp4` movie stored in `raw` folder? – Cătălin Florescu Jun 09 '17 at 21:10
  • 1
    @PC. could you avoid writing comments to answers to unrelated questions with the sole purpose of linking to this question? – SirDarius Jun 11 '17 at 09:39

1 Answers1

2

The culprit here is android.widget.VideoView which extends SurfaceView.

This blog says:

Playing a video using a VideoView inside of a row of a ListView seems to work at first, until the user tries to scroll the list. As soon as the list starts to scroll, the video turns black (sometimes displays white). It keeps playing in the background but you can’t see it anymore because it renders the rest of the video as a black box.

I wrote my own VideoView class which extends TextureView with the help of this github repository. Though It has some issues as it was written 3 years ago I managed to fix them on my own. Very soon I'll update this answer with my custom Optimized VideoView github repository (just with few modifications). Until then, the link which I've provided would help you.

With the custom Optimized VideoView, the videos will play on scroll in the ListView just like our Instagram, Facebook, Twitter. We can make the videos play/pause by setting setOnTouchListener() on VideoView in our activity and can customize it in our own way.

Now, our VideoView in the Layouts would be:

<your.packagename.VideoView
    android:id="@+id/admin_video_view"
    android:layout_width="300dp"
    android:layout_height="300dp" />
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
coderpc
  • 4,119
  • 6
  • 51
  • 93
  • I would be curious to know if it worked with `RecyclerView` (without the aid of an external library), but I'm glad you got `ListView` working. – Suragch Jul 05 '17 at 23:54
  • Don't forget to link to your new optimized repository when it is ready. – Suragch Jul 05 '17 at 23:57