[关闭]
@gogogodeng 2017-08-10T13:43:20.000000Z 字数 1009 阅读 515

VideoView

android控件


播放音视频的控件

布局代码

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent">
  6. <VideoView
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content"
  9. android:id="@+id/videoView"
  10. android:layout_gravity="center_horizontal"
  11. android:layout_centerInParent="true" />
  12. </LinearLayout>

java代码

  1. package com.testapp.app;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.net.Uri;
  5. import android.widget.VideoView;
  6. /**
  7. * Created by develop on 2015/11/17.
  8. */
  9. public class VideoViewActivity extends Activity {
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.videoview);
  14. // 开启新的线程
  15. Thread t=new Thread(new Runnable() {
  16. @Override
  17. public void run() {
  18. VideoView vv = (VideoView)findViewById(R.id.videoView);
  19. vv.setVideoURI(Uri.parse("http://192.168.1.254/UploadFiles/d/test.mp4"));
  20. vv.start();
  21. }
  22. });
  23. t.start();
  24. }
  25. }

不开启新线程就报错

效果

效果图

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注