res/raw
フォルダに保存されている 2 つのローカル ビデオを再生する Google TV アプリケーションを作成しました。アプリケーションは正常に実行を開始しますが、ランダムな時間にロックアップします。ロックアップした後、「申し訳ありませんが、このビデオを再生できません」というメッセージが表示されます。アプリケーションを再起動しようとするとメッセージが表示されます。また、私のアプリケーションが影響を受けるだけでなく、YouTube アプリのように、他のすべてのアプリケーションのビデオ再生が影響を受けるようです。システムを再起動してもエラーは解決しません。他の誰かがこのようなことに遭遇したことがありますか、または何が原因である可能性があるか考えていますか?
これが私のコードで、SonyNSZ-GS7 で実行されています。
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;
}
}
}
そしてレイアウト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>