0

Android App says can't play video on button click

I deployed an app to my smartphone and it was just a simple project to test a video view's functionality. I have xml code i used to design the button that calls the playVideo() function from the MainActivity java class Here is my xml code for the button with the android:onClick trigger <Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="playVideo" android:text="@string/Button1" /> And here is the MainActivity.java embedded code that takes care of playing the video when the button is clicked package com.example.videoplayer; import android.net.Uri; import android.os.Bundle; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.widget.MediaController; import android.widget.VideoView; public class MainActivity extends AppCompatActivity { public void playVideo(View v) { //Your code here// MediaController m = new MediaController(this); String path = "android.resource://com.aasemjs.videoplayer/"+R.raw.rain; Uri u = Uri.parse(path); VideoView vid = (VideoView) findViewById(R.id.videoView); vid.setVideoURI(u); vid.start(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); VideoView vid = (VideoView) findViewById(R.id.videoView); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View

18th Aug 2020, 2:49 PM
Timothy Njiru
Timothy Njiru - avatar
1 Respuesta
0
@Thesmallest, Does android support mp4 video format?
18th Aug 2020, 4:56 PM
Timothy Njiru
Timothy Njiru - avatar