tags:

views:

26

answers:

1

I am working on Anroid (with Eclipse and SDK) trying to stream video into a VideoView. Sometimes the video works, but other times I get an error that the video cannot be displayed. Here is the code:

//video

    private Uri mPath;

private VideoView mVid;

    mPath = Uri.parse("android.resource://com.accuweather.wordweather/" + R.raw.b2);

    mVid.setVideoURI(mPath);

    mVid.requestFocus();

    mVid.start();

And another class that loads different videos when a user scrolls the screen.

public void onScrollViewSnap(int page) {
    //change video
    Log.d(DEB_TAG, "In 'onPageCountChange: '." + page);
    //video

    if(page != mOnPage){
        if(page == 0){
            mPath = Uri.parse("http://www.ted.com/talks/download/video/8584/talk/761");
            //mPath = Uri.parse("android.resource://com.accuweather.wordweather/" + R.raw.w2);
        }else if(page == 1){
            mPath = Uri.parse("android.resource://com.accuweather.wordweather/" + R.raw.b1);
        }else if(page == 2){
            mPath = Uri.parse("http://commonsware.com/misc/test2.3gp");
            //mPath = Uri.parse("android.resource://com.accuweather.wordweather/" + R.raw.test2);
        }
        if(mVid.isPlaying() == true){
            mVid.stopPlayback();
        }
        mVid.setVideoURI(mPath);
        mVid.requestFocus();
        mVid.start();
        Log.d(DEB_TAG, "THIS IS THE HEIGHT: " + mVid.getMeasuredHeight());
        Log.d(DEB_TAG, "THIS IS THE WIDTH: " + mVid.getMeasuredWidth());
    }

    ImageView temp = null;

    switch(page){
    case 0:
        temp = (ImageView) findViewById(R.id.scroll_page_1);
        mOnPage = 0;
        break;
    case 1:
        temp = (ImageView) findViewById(R.id.scroll_page_2);
        mOnPage = 1;
        break;
    case 2:
        temp = (ImageView) findViewById(R.id.scroll_page_3);
        mOnPage = 2;
        break;
    }

    // Change pagination image
    mPageSelected.setImageResource(R.drawable.scrollview_page_off);
    temp.setImageResource(R.drawable.scrollview_page_on);
    mPageSelected = temp;

}

First, does loading my video this way ensure that it will be displayed alike on each different device?
Second, any idea why a video will start to play and then kick an error of video not able to play? Here is what I get in LogCat when video starts but locks up.

07-01 13:27:05.594: WARN/PlayerDriver(30): Using generic video MIO
07-01 13:27:22.324: WARN/PlayerDriver(30): Video track fell behind
07-01 13:27:22.324: ERROR/MediaPlayer(409): error (1, 48)
07-01 13:27:22.324: ERROR/MediaPlayer(409): Error (1,48)
07-01 13:27:22.324: DEBUG/VideoView(409): Error: 1,48
A: 

Video playback on emulator is not very stable. You should test and develop on at least one real device if you're working with video a lot. It's a common issue.

Mathias Lin
Thanks! It works on an actual device.
taraloca