[Video] Gap on VideoView

All your problems with Audio, Video and Images.

[Video] Gap on VideoView

Postby Leucistic » Mon Jul 26, 2010 2:37 pm

Hi all,

I'm new to the android platform and I've got an XPERIA X10 (Android 1.6).

Here is my problem :
I want to display a list of video files stored on sdcard. I'm able to display them on a VideoView, but there is a gap (500ms of black) between two videos, and I don't know how remove it.
I have tried to implement two VideoViews in order to prepare the second while the first is playing, but I can't find a prepare() method.
I've also tried the bringToFront() but it doesn't work ...

Have you any ideas of how can I remove this gap ?

Thanks in advance.

PS : I'm French and I apologize if my english is not perfect.
Leucistic
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 26, 2010 2:13 pm

Top

Re: [Video] Gap on VideoView

Postby blundell » Tue Jul 27, 2010 8:19 am

Tried preparing the next video in another thread?
What is the gap for? Is it while the video is being prepared? Surface being created?
Find out where the delay is occuring with some Log.i("logCat","debug");
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: [Video] Gap on VideoView

Postby Leucistic » Tue Jul 27, 2010 10:24 am

Actually, I've one VideoView declared on my xml, and then linked in my main Activity.
When I want to display a video, I use setVideoURI(Uri.parse("/sdcard/video/vid.mp4") and start() method.

The gap appears when the setVideoURI is called. So I suppose that the setVideoURI method call the prepare() method.

To avoid this gap, I should use two VideoViews, but how can I superpose two VideoViews to bring one to the front, then bring the other one on top ?
Leucistic
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 26, 2010 2:13 pm

Re: [Video] Gap on VideoView

Postby blundell » Tue Jul 27, 2010 11:55 am

Hmm you could try a Framelayout, this put's all child elements on top of each other. Therefore theoretically it's possible.
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: [Video] Gap on VideoView

Postby Leucistic » Wed Jul 28, 2010 10:01 am

I've tried this :

Code: Select all
        l = (FrameLayout)findViewById(R.id.FrameLayout01);
        video1 = new VideoView(this);
        video2 = new VideoView(this);
       
       
        l.addView(video1);
        video1.setVideoURI(Uri.parse("/sdcard/video/fifa.mp4"));
        video1.start();
       
        l.setOnClickListener(new OnClickListener() {
         
         @Override
         public void onClick(View v) {
            if (i==0)
            {   
               l.addView(video2);
               video2.setVideoURI(Uri.parse("/sdcard/video/My World.mp4"));
               video2.start();
                 video2.pause();
               
               i++;
            }
            else if (i==1)
            {
               video1.stopPlayback();
               l.removeView(video1);
               video2.start();      
               i = 0;
            }
         }
      });


The gap is shorter than previously, but it still remains.
I've tried to use a MediaPlayer but I'm not able to display any video :cry:
There isn't any fader or transition features availables ?
Leucistic
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 26, 2010 2:13 pm

Re: [Video] Gap on VideoView

Postby blundell » Wed Jul 28, 2010 10:17 am

I'd recommend trying again to switch over to a MediaPlayer. The problem I had when I couldn't display video (only audio) was I wasn't waiting for the surface to be created and just playing in the onCreate.

This is just a snippet and will not work on its own:
Code: Select all
player = new MediaPlayer();
player.prepare();
player.setOnPreparedListener(this);     
player.setOnVideoSizeChangedListener(this);


Code: Select all
public void onPrepared(MediaPlayer mediaplayer) {
                mIsVideoReadyToBePlayed = true;         
                if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
            startVideoPlayback();
        }


Code: Select all
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {               
        mIsVideoSizeKnown = true;
        this.width = width;
        this.height = height;
        if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
            startVideoPlayback();
        }
        }


It's fully documented here: http://developer.android.com/resources/ ... Video.html
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Re: [Video] Gap on VideoView

Postby Leucistic » Wed Jul 28, 2010 10:27 am

I've already see your link but it doesn't work.
How do you set the surface ?
Leucistic
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 26, 2010 2:13 pm

Re: [Video] Gap on VideoView

Postby blundell » Wed Jul 28, 2010 10:42 am

The surface is simply set in the XML
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/bg_splash">
        <SurfaceView
                android:id="@+id/surface"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center">
        </SurfaceView>
</FrameLayout>
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: [Video] Gap on VideoView

Postby Leucistic » Wed Jul 28, 2010 10:54 am

And you do nothing on the .java ?

mp.setDisplay(surface.getHolder());
generate an error when i execute the app.
Leucistic
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 26, 2010 2:13 pm

Re: [Video] Gap on VideoView

Postby blundell » Wed Jul 28, 2010 11:36 am

I do this to the holder:
Code: Select all
holder = surface.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);


And I don't call setDisplay until I get a callback from this method
Code: Select all
public void surfaceCreated(SurfaceHolder holder) {
               
}
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: [Video] Gap on VideoView

Postby Leucistic » Wed Jul 28, 2010 12:30 pm

Code: Select all
package com.sony.test.mediatest;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class MediaTest extends Activity implements SurfaceHolder.Callback, MediaPlayer.OnPreparedListener {
   MediaPlayer mp = new MediaPlayer ();
   SurfaceView s = null;
   SurfaceHolder sh = null;
   
   /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        s = (SurfaceView) findViewById(R.id.SurfaceView01);
        sh = s.getHolder();
        sh.addCallback(this);
        sh.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
       
        try
        {
         mp.setDataSource("/sdcard/video/Tutorial.mp4");
         mp.prepare();
      }
        catch (Exception e)
      {
         Log.e("ZirisNano", e.getMessage());
      }
    }

   @Override
   public void surfaceChanged(SurfaceHolder holder, int format, int width,
         int height) {
      Log.d("ZirisNano", "Surface Changed");
   }

   @Override
   public void surfaceCreated(SurfaceHolder holder) {
      Log.d("ZirisNano", "Surface Created");
      mp.setDisplay(sh);
   }

   @Override
   public void surfaceDestroyed(SurfaceHolder holder) {
      Log.d("ZirisNano", "Surface Destroyed");
   }

   @Override
   public void onPrepared(MediaPlayer mp) {
      Log.d("ZirisNano", "Media Player Prepared");
      mp.start();
   }
}


Here is my test class. On my main.xml, I've got only a SurfaceView named SurfaceView01.
When I launch it, nothing happens except SurfaceCreated and SurfaceChanged. I've got no video and no audio...
Leucistic
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 26, 2010 2:13 pm

Re: [Video] Gap on VideoView

Postby blundell » Wed Jul 28, 2010 1:51 pm

You haven't implemented it the same as the example I showed you:
http://developer.android.com/resources/ ... Video.html

Please read carefully,

Your missing the on video size changed call, how can it play a video if you haven't loaded it?

Try again
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: [Video] Gap on VideoView

Postby Leucistic » Wed Jul 28, 2010 2:38 pm

I've made a select all/copy/paste of the example. I've had an NullPointerException due to extras. As I only want to play local videos, I've removed it and MediaPlayer works fine.

Now I'm going to try to understand the code.

Thanks for your help and your patience.
Leucistic
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 26, 2010 2:13 pm

Re: [Video] Gap on VideoView

Postby Leucistic » Thu Jul 29, 2010 3:15 pm

Hi,

I've made a class of this example, and it works.
Now, I want to instanciate two of these in order to prepare one when the other plays. But if the surface isn't displayed, the onSurfaceCreated event is never called.

So, I've put the same surface for the first and the second mediaPlayer object, onSurfaceCreated, onPrepared methods are called. When I run that, the first video is totally green (but audio is playing). When I ask to the second to be played at the end of the first, audio and video are played well.

Do you have any ideas/solutions ?
Leucistic
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 26, 2010 2:13 pm

Re: [Video] Gap on VideoView

Postby fusuke » Thu Jul 29, 2010 8:11 pm

Hi,every one. also I am facing the similar problem.

I want to zoom out a small vide0View to full screen as the below illustration.

Image

My solution is reconnecting for these tow VideoView objects. However, the solution is not good because two reason:
- Delay lager time,the DataSource is rtsp streaming from network.
- Have to playing from begin of streaming(not good for online streaming)

I searching a new solution for above problems.
Who have the idea to solusive the problems ?

Thanks!
Last edited by fusuke on Thu Jul 29, 2010 8:13 pm, edited 1 time in total.
fusuke
Freshman
Freshman
 
Posts: 4
Joined: Fri Jul 09, 2010 8:04 pm

Top
Next

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 12 guests