简体   繁体   English

Xamarin“对不起,此视频无法播放”

[英]Xamarin “Sorry, this video cannot be played”

How can i handle this error? 我该如何处理该错误? please help me out of this situation. 请帮助我摆脱这种情况。

private void previewVideo(){

            try{

            var path = Android.Net.Uri.Parse(App._file.AbsolutePath);

            preview.SetVideoURI (path);

            preview.Start ();

            }

            catch(Exception e){
                e.GetBaseException ();
            }

        }

Your'e lucky that I was following your previous question. 您很幸运,我一直在关注您之前的问题。 Please try to have your questions as detailed as possible so it's easier for us to analyze and possible replicate the error. 请尝试尽可能详细地回答您的问题,以便我们更轻松地分析并可能复制错误。

To be able to set an error listener on the VideoView, the VideoView needs an object that implements the Android.Media.MediaPlayer.IOnErrorListener interface. 为了能够在VideoView上设置错误侦听器,VideoView需要一个实现Android.Media.MediaPlayer.IOnErrorListener接口的对象。

You can accomblish that by letting your Activity implement the previous mentioned interface, and setting the Activity as the ErrorListener for the VideoView 您可以通过让您的Activity实现前面提到的界面,并将Activity设置为VideoView的ErrorListener来实现这一点

public class MainActivity : Activity, Android.Media.MediaPlayer.IOnErrorListener
{

    ...

    protected override void OnCreate(Bundle bundle)
    {
        ...
        preview = FindViewById<VideoView> (Resource.Id.SampleVideoView);
        preview.SetOnErrorListener(this); // <- Set the error listener
        ...
    }

    ...

    //The implementation of MediaPlayer.IOnErrorListener
    public bool OnError(MediaPlayer player, MediaError error, int extra)
    {
        // Do Something here because error happened
    }

    ...
}

By doing this, when error occurs in the VideoView the VideoView will call the public OnError method. 这样,当VideoView中发生错误时,VideoView将调用公共OnError方法。

From the Android Docs of OnErrorListener you can see what the OnError method should return. OnErrorListenerAndroid文档中,您可以看到OnError方法应该返回什么。

Returns : 返回值

True if the method handled the error, false if it didn't. 如果该方法处理了错误,则为true,否则为false。 Returning false, or not having an OnErrorListener at all, will cause the OnCompletionListener to be called. 返回false或完全没有OnErrorListener,将导致调用OnCompletionListener。

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

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