视频无法正常显示

发布于 2024-09-07 19:25:06 字数 2430 浏览 0 评论 0原文

我正在 Android(使用 Eclipse 和 SDK)上工作,尝试将视频流式传输到 VideoView 中。有时视频可以播放,但有时会出现视频无法显示的错误。这是代码:

//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();

另一个类在用户滚动屏幕时加载不同的视频。

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;

}

首先,以这种方式加载我的视频是否可以确保它在每个不同的设备上都以相同的方式显示?
其次,知道为什么视频会开始播放然后出现视频无法播放的错误吗? 以下是当视频开始但锁定时我在 LogCat 中得到的结果。

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

I am working on Android (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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眼泪 2024-09-14 19:25:06

模拟器上的视频播放不是很稳定。如果您经常使用视频,则应该在至少一台真实设备上进行测试和开发。这是一个常见问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文