简体   繁体   English

无法播放此视频Xamarin.Android

[英]Can't play this video Xamarin.Android

I need to play video from sdcard on VideoView and always getting "Can't play this video message". 我需要在VideoView上播放SD卡上的视频,并始终收到“无法播放此视频消息”。 I am testing on physical device. 我在物理设备上测试。 File is on external storage, and can be played by build in phone apps with no problem. 文件位于外部存储器上,可以通过内置手机应用程序播放,没有任何问题。

I have read some topics before and tried changing file format and resolution with no effect. 我之前已阅读过一些主题,并尝试更改文件格式和分辨率,但没有任何效果。

Second guess was path to the file so tried to change it multiple times in many variants using Android.OS.Environment.ExternalStorageDirectory.AbsolutePath , creating File variable and getting path from File.Path . 第二个猜测是文件的路径,因此尝试使用Android.OS.Environment.ExternalStorageDirectory.AbsolutePath在许多变体中多次更改它,创建File变量并从File.Path获取路径。

Got the TextView where I put path every time and it is always correct. 得到TextView我每次都放置路径,它始终是正确的。

I have no idea why it does not work. 我不知道为什么它不起作用。

Code: 码:

Java.IO.File file = new Java.IO.File (Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/myimage/", "video.mp4");

tView.Text = file.Path;

MediaController mediaController = new MediaController(context: this);
vView.SetMediaController(mediaController);
mediaController.SetAnchorView(vView);
vView.SetVideoPath(file.Path);
vView.Start();

File.Path value: File.Path值:

"/storage/emulated/0/myimage/video.mp4"

EDIT: I have created "raw" folder in resource putted file there and then used following path: 编辑:我在资源putted文件中创建了“原始”文件夹,然后使用以下路径:

vView.SetVideoPath("android.resource://" + PackageName + "/" + Resource.Raw.video);

It works, but if anyone know how to get the proper path to folder on sdCard? 它有效,但如果有人知道如何在sdCard上获得正确的文件夹路径?

Finally I figured it out. 最后我明白了。 The problem was that my phone mounted card at path /storage/xxxx-xxxx/ my research revealed that the dir's name come from volume serial number(where android automatically mount card) and ExternalStorageDirectory refers to other locations in each android device. 问题是我的手机卡在路径/ storage / xxxx-xxxx /我的研究显示,dir的名字来自卷序列号(其中android自动挂载卡)和ExternalStorageDirectory指的是每个Android设备中的其他位置。 Sometimes it's internal sometimes usb mass storage. 有时它内部有时是usb大容量存储。

Anyway didn't manage to find any method that returns the path so created following method: 无论如何都没有设法找到任何方法返回如下创建的路径:

string GetCardMountPoint()
    {
        string[] listOfDirs = Directory.GetDirectories("/storage/");
        string path = null;

        foreach ( string dir in listOfDirs)
        {
            if(dir.Contains('-'))
            {
                path = dir;
            }
        }

        return path;

It's not much of sophisticated solution but it works for now. 它不是很复杂的解决方案,但现在可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM