在VideoView中播放来自网址的视频[Android] [英] Play video from url in VideoView [Android]

查看:256
本文介绍了在VideoView中播放来自网址的视频[Android]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了类似的问题,但对我来说没什么用。
我尝试从这个网址播放视频:

I found a similar questions but nothing work for me. I try play video from this url:

http://videocdn.bodybuilding.com/video/mp4/62000/62792m.mp4

我的java代码:

VideoView videoView= (VideoView)findViewById(R.id.exerciseVideo);
    Uri uri = Uri.parse(TEST_URL);
    videoView.setVideoURI(uri);
    videoView.requestFocus();
    videoView.start();

当我运行app时,活动中不会显示任何内容,IDE也不会显示任何错误。有什么想法吗?

When I run app nothing is displayed in activity and IDE does not show any errors. ANy idea, please?

编辑:

我想要播放视频的活动:

My activity where I want to show video:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <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:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.martin.fitnessapp.ExerciseDetailActivity"
        android:orientation="vertical">


        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="2">
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/exerciseImgA"
                android:layout_weight="1"
                android:scaleType="fitCenter"
                android:adjustViewBounds="true"
                android:paddingRight="8dp"/>

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/exerciseImgB"
                android:layout_weight="1"
                android:scaleType="fitCenter"
                android:adjustViewBounds="true"
                android:paddingLeft="8dp"/>
        </LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text=""
            android:id="@+id/exerciseDesc" />

        <VideoView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/exerciseVideo" />

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/guideImg"
            android:scaleType="fitCenter"
            android:adjustViewBounds="true"/>


    </LinearLayout>
</ScrollView>


推荐答案

试试这段代码..这段代码非常适合我..

Try this code.. This code works perfectly for me..

    final VideoView videoView;
    videoView = (VideoView)findViewById(R.id.videoView);
    videoView.setVideoPath("http://videocdn.bodybuilding.com/video/mp4/62000/62792m.mp4");
    videoView.start();

这篇关于在VideoView中播放来自网址的视频[Android]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆