【问题标题】:How to display mp4 video in videoview from raw folder如何在 raw 文件夹中的 videoview 中显示 mp4 视频
【发布时间】:2016-09-30 00:43:05
【问题描述】:

我正在尝试显示原始文件夹中的 mp4 视频。当应用程序打开时,视频应该会自动在 videoview 中播放。我希望视频在活动启动后立即开始(这是启动器活动)。我还希望视频循环播放并且没有声音。我的 xml 在下面。

<VideoView
    android:id="@+id/launcherVideo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/linearLayout" />

这是我的代码。

String fileName = "android.resource://"+ getPackageName()+"/raw/launchervideo";

VideoView mvideo = (VideoView) findViewById(R.id.launcherVideo);

mvideo.setVideoPath(Launcher);

MediaController controller = new MediaController(this);

mvideo.setMediaController(controller);

mvideo.requestFocus();

mvideo.start();

}

当我运行应用程序时,这段代码目前除了显示一个空白屏幕之外什么也没做,我不知道为什么。有人可以帮忙吗?

【问题讨论】:

    标签: android video


    【解决方案1】:

    我没有看到你使用这个变量,也没有看到你如何定义Launcher 变量。

    String fileName = "android.resource://"+ getPackageName()+"/raw/launchervideo";
    

    要从原始文件夹打开视频文件,您可以这样做:

    Uri uri = Uri.parse(fileName);
    mvideo.setVideoURI(uri);
    mvideo.start()
    

    希望能帮到你解决问题

    【讨论】:

    • 你应该在视图绑定之后调用它(在这行代码之后)VideoView mvideo = (VideoView) findViewById(R.id.launcherVideo);
    【解决方案2】:

    感谢各位大神帮忙,我搞定了。

    VideoView videoView = (VideoView) findViewById(R.id.launcherVideo);
        Uri src = Uri.parse("android.resource://com.package/raw/video_name");
        videoView.setVideoURI(src);
    
        //videoView.setMediaController(new MediaController(this));
    
        videoView.start();
    

    这对我有用。

    【讨论】:

      猜你喜欢
      • 2018-07-16
      • 2013-06-28
      • 2019-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-17
      相关资源
      最近更新 更多