Open your main XML file and drag VideoView and a button or paste below code:
</RelativeLayout>
Now open your Java file and paste below code:
importandroid.os.Bundle;
Now run your project...only video will display on VideoView if we are playing audio file than nothing will display but we can listen audio.
<RelativeLayout xmlns:android="http://schemas. android.com/apk/res/android"
xmlns:tools="http://schemas. android.com/tools"
android:layout_width="match_ parent"
android:layout_height="match_ parent"
android:paddingBottom="@dimen/ activity_vertical_margin"
android:paddingLeft="@dimen/ activity_horizontal_margin"
android:paddingRight="@dimen/ activity_horizontal_margin"
android:paddingTop="@dimen/ activity_vertical_margin"
tools:context=".MainActivity">
<VideoView
android:id="@+id/videoView1"
android:layout_width="300dp"
android:layout_height="200dp"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_ content"
android:layout_height="wrap_ content"
android:layout_below="@+id/ videoView1"
android:layout_ centerHorizontal="true"
android:layout_marginTop=" 15dp"
android:text="Play"
android:onClick="play" />
Now open your Java file and paste below code:
package jaggu.suhail; //your package name
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.VideoView;
importandroid.app.Activity;
public class MainActivity extends Activity {
VideoView v;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState);
setContentView(R.layout.activi ty_main);
v=(VideoView)findViewById(R. id.videoView1);
//give Video or audio path of sdcard here
v.setVideoPath("/sdcard/Music/ BigB.mp4");
}
public void play(View view)
{
v.start();
}
}
Now run your project...only video will display on VideoView if we are playing audio file than nothing will display but we can listen audio.
0 komentar:
Posting Komentar