import android.widget.VideoView;
import android.widget.MediaController;
// to control media i.e; stop, play, pause
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// start coding from here
final VideoView buckysVideoView = (VideoView) findViewById(R.id.buckysVideoView);
buckysVideoView.setVideoPath("https://www.thenewboston.com/forum/project_files/006_testVideo.mp4");
// applying mediaControler properties
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(buckysVideoView);
buckysVideoView.setMediaController(mediaController);
buckysVideoView.start();
}
}
答案 0 :(得分:1)
如果视频存储在您的设备上,请不要使用setVideoPath
,您应该使用setVideoURI
通过http进行视频。
String urlStrinh = "https://www.thenewboston.com/forum/project_files/006_testVideo.mp4";
VideoView buckysVideoView = (VideoView) findViewById(R.id.buckysVideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(buckysVideoView);
Uri videoURI = Uri.parse(urlString);
buckysVideoView.setMediaController(mediaController);
buckysVideoView.setVideoURI(videoURI);
buckysVideoView.start();