【问题标题】:Play a mp4 file in android videoview在 android videoview 中播放 mp4 文件
【发布时间】:2014-01-03 18:40:44
【问题描述】:

我正在尝试在我简单的 android VideoView 中播放 mp4 视频。这是我的代码

VideoView videoView;
videoView = (VideoView) findViewById(R.id.videoViewa);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
//URI either from net
Uri video = Uri.parse("http://www.fieldandrurallife.tv/videos/Benltey%20Mulsanne.mp4");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();

我的布局看起来像

<RelativeLayout 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=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

<VideoView
    android:id="@+id/videoViewa"
    android:layout_width="match_parent"
    android:layout_gravity="center"
    android:layout_height="match_parent" />


</RelativeLayout>

清单看起来像

    android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

我在尝试启动应用程序时收到以下错误

Couldn't open file on client side, trying server side
error (1, -1004)

有没有人遇到过同样的情况?

请帮忙 提前致谢

【问题讨论】:

  • 已修复!!!对于有同样问题的人,请注意 Android 将仅播放 H.264 压缩视频。一旦我尝试使用上述视频,问题就解决了

标签: android video-streaming android-videoview android-video-player


【解决方案1】:

您的代码看起来不错,我认为问题出在服务器端。我不知道你是如何使用你的服务器的。但是尝试使用您自己的服务器。 请设置一个 Apache 网络服务器来测试您的本地视频。设置Apache的教程是here

如果你不想使用自己的服务器,请使用在线mp4链接here,这是我使用的测试文件。

测试此链接的最简单方法是使用网络浏览器打开链接以检查文件是否可访问,只需将 URL 复制粘贴到浏览器即可。

如果您已经拥有“adb”,您也可以在您的 android 端测试该链接。使用命令:

adb shell am start -a android.intent.action.VIEW -d http://169.228.179.91/username/abc.mp4

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-07
    • 2013-06-28
    • 1970-01-01
    • 2011-08-10
    • 2018-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多