0

I added the following code to my app to add a video view which is linked to a video in my raw folder but I'm getting an error on VideoView saying that VideoView cannot be resolved or is not a fieldI have included all the relevant imports.Is the an error somewhere in my syntax?

VideoView StudentLife = (VideoView) findViewById(R.id.VideoView);

        Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.learningatgmi);

        videoview.setVideoURI(uri);
        videoview.start();  

My xml layout for videoview is as follows:

<VideoView
        android:id="@+id/videoView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="53dp" />
4

4 に答える 4

4

だからあなたの変数名はStudentLife

VideoView StudentLife = (VideoView) findViewById(R.id.VideoView);

そして、未定義の変数である他のメソッドを呼び出してvideoviewいます..

したがって、次のコード:

        videoview.setVideoURI(uri);
        videoview.start();  

次のようにする必要があります。

        StudentLife.setVideoURI(uri);
        StudentLife.start();  

EDIT1:

XMLによると、ビデオビューのインスタンスを取得する行は次のとおりです

VideoView StudentLife = (VideoView) findViewById(R.id.videoView1);

完全に機能するコードは次のようになります。

VideoView StudentLife = (VideoView) findViewById(R.id.videoView1);
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.learningatgmi);
StudentLife.setVideoURI(uri);
StudentLife.start();  

側ではありません。クラス名を変数名として使用しないでください... Javaでも変数の最初の文字を大文字にしないでください...変数名として「videoView」を使用しましょう..変数名の種類..

VideoView videoView = (VideoView) findViewById(R.id.videoView1);
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.learningatgmi);
videoView.setVideoURI(uri);
videoView.start();  
于 2013-03-19T12:42:15.270 に答える
1

あなたのIDVideoViewvideoView1. したがって、次をVideoView使用してビュー階層からオブジェクトへの参照を取得する必要がありますR.id.videoView1

 VideoView StudentLife = (VideoView) findViewById(R.id.videoView1);
 Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.learningatgmi);
 StudentLife.setVideoURI(uri);
 StudentLife.start();  
于 2013-03-19T12:43:30.833 に答える
0

実際にこのコードを使用すると、

Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.learningatgmi);
StudentLife.setVideoURI(uri);

URIをnullとして渡すため、エラーが表示されるため、代わりに次のコードを使用できません。

StudentLife=(VideoView)findViewById(R.id.videoplayer);
StudentLife.setVideoURI(Uri.parse("android.resource://" +getPackageName()+ "/" +R.raw.sample));
StudentLife.requestFocus();
StudentLife.start();

設定前に URI をパースするのではなく、設定時に渡した方が良いでしょう。

于 2013-11-26T06:59:57.873 に答える
0

私のコードは動作します::

mc = new MediaController(this);
vd.setMediaController(mc);
vd.setVideoURI(intentUri);
vd.start();
setContentView(vd);
于 2013-03-19T12:40:08.773 に答える