Android视频视图中损坏的图片

时间:2016-02-01 13:26:12

标签: android android-videoview

我正在开发rtsp视频播放器应用。我使用默认的videoView小部件来实现我的目标。我的代码如下:

public class MainActivity extends AppCompatActivity {

    VideoView videoView;
    String path;
    Button btn;
    EditText editText;
    MediaController mediaController;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn=(Button)findViewById(R.id.button);
        editText=(EditText)findViewById(R.id.editText);
        videoView = (VideoView) findViewById(R.id.videoView);
        mediaController = new MediaController(this);
        mediaController.setMediaPlayer(videoView);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                path=editText.getText().toString();
                Uri video = Uri.parse(path);
                videoView.setMediaController(mediaController);
                videoView.setVideoURI(video);
                videoView.start();
            }
        });
    }

}

和activity_main:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.yonder.denemetahtasi4.MainActivity">


    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
  />

    <VideoView
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:id="@+id/videoView"
         />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button" />

</LinearLayout>

视频已开始但图像已损坏,如下图所示:

enter image description here

我的错误在哪里?也许我应该用这个库?

0 个答案:

没有答案