0

I created a Google TV application that plays two local videos stored in the res/raw folder. The application starts running fine, but then locks up at random times. After it locks up, I get the "Sorry, cannot play this video." message when I try to restart the application. And not only is my application affected, but all other application video playback seems to be affected like the YouTube app. The error persists even after restarting the system. Has anybody else encountered anything like this, or has an idea on what may be causing it?

Here is my code, running on SonyNSZ-GS7:

The MainActivity:

public class MainActivity extends Activity {

    int currentVideo = R.raw.ahwvideo;
    VideoView videoView;

    @SuppressLint("DefaultLocale")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.activity_main);

        // Code to Display Video
        videoView = (VideoView)findViewById(R.id.VideoView);          
        videoView.setVideoURI(Uri.parse(
                "android.resource://" + getPackageName() +"/"+R.raw.ahwvideo1));
        videoView.setMediaController(new MediaController(this));
        videoView.requestFocus();       
        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

            public void onCompletion(MediaPlayer mp) {
                switchVideo(videoView);
                videoView.start();
            }
        });

        videoView.start();
    }

    public void switchVideo(VideoView videoView) {
        if (currentVideo == R.raw.ahwvideo1) {
            videoView.setVideoURI(Uri.parse("android.resource://"
                    + getPackageName() +"/"+R.raw.ahwvideo2));
            currentVideo = R.raw.ahwvideo2;
        } else {
            videoView.setVideoURI(Uri.parse("android.resource://"
                    + getPackageName() +"/"+R.raw.ahwvideo1));
            currentVideo = R.raw.ahwvideo1;
        }
    }
}

And the layout activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity" >

    <VideoView
        android:id="@+id/VideoView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</RelativeLayout>

2 Answers2

0

Don't know if it really matters but it seems there is an error in the video name:

videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/"+R.raw.video2));

Should be: R.raw.*ahw*video2

libeasy
  • 379
  • 2
  • 11
  • Thanks libeasy, I must have erased that when I added the code to the post...I actually did have it as R.raw.ahwvideo2 in my program – Hilario Urquieta Mar 27 '13 at 20:47
0

In switchVideo(), add at the beginning:

videoView.setVisibility(View.GONE);

and at the end:

videoView.setVisibility(View.VISIBLE);

so that it encloses the setVideoURI(). I know, it seems odd, but give it a try and say if it makes a difference.

libeasy
  • 379
  • 2
  • 11
  • The error has not ocurred anymore. Thanks libeasy. How did you come about that suggestion? It is odd that hiding and show the view solved the issue. – Hilario Urquieta Apr 04 '13 at 21:04