0

i currently am using this code to play both audio and video files but I need to be able to stop the video/audio file after a specific time frame like 30 seconds. Is it possible using videoview and the mediacontroller I have been trying but unsuccessfully.

Could someone give me some code snippets that would perform this functionality.

public class AudioActivity extends Activity {
TextView audioTitleValue;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /** REMOVE TITLE **/
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.moveplay);
    overridePendingTransition(R.anim.fadein, R.anim.fadeout);

    final VideoView audioView = (VideoView) findViewById(R.id.VideoView);
    final MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(audioView);

    Bundle extras = getIntent().getExtras();
    String pathfile = extras.getString("key");
    Log.v("key = ",pathfile);

    Uri audio = Uri.parse(pathfile);
    audioView.setMediaController(mediaController);
    audioView.setVideoURI(audio);
    audioView.start();
}

}

and the associated xml file

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical" >
<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="35dp" >
    <TextView
        android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:paddingLeft="25dp"
        android:paddingTop="7dp"
        android:text="@string/app_name"
        android:textColor="#999999" />
</LinearLayout>
<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:paddingTop="35dp"
    android:src="@drawable/musicplayergraphic" />
<VideoView
    android:id="@+id/VideoView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</VideoView>

Jeff Janes
  • 885
  • 1
  • 8
  • 22

0 Answers0