编译应用程序时出错

时间:2016-12-05 22:50:29

标签: c# visual-studio xamarin.android

我试图创建应用程序以从ip camera流式传输实时视频。我正在使用本教程:click 但是当我尝试启动应用程序时,我有这个例外:

  

Android.Views.InflateException:二进制XML文件行#1:二进制XML文件行#1:错误输出类com.camera.simplemjpeg.MjpegView

我试图解决这个问题,但我真的不知道如何修复它。 我的代码:

MainActivity.cs:

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Com.Camera.Simplemjpeg;
using System.Threading.Tasks;

namespace IP_Cam_View
{
    [Activity(Label = "IP_Cam_View", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        //MjpegView instance
        private MjpegView mv = null;
        //Play button
        Button button = null;
        //UI EditText with URL
        EditText txturl = null;
        //Streaming URL
        String URL = "http://webcam.st-malo.com/axis-cgi/mjpg/video.cgi?resolution=640x480";
        //Layout sizes for video view
        private int width = 640;
        private int height = 480;
        //Suspendign straming bool variable
        private bool suspending = false;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            //initialize mjpeg view with UI Android XML
            mv = FindViewById<MjpegView>(Resource.Id.mv);
            //check if the instance is valid
            if (mv != null)
            {
                //set the resolution of streaming
                mv.SetResolution(width, height);
            }
            //assignation of UI items 
            button = FindViewById<Button>(Resource.Id.myButton);
            txturl = FindViewById<EditText>(Resource.Id.editText1);
            //button click event
            button.Click += delegate
            {
                //take URL from txturl(EditText) field
                URL = txturl.Text;
                //Begin a task method to streaming
                BeginStreaming(URL);
            };
            //Begin a task method to streaming
            BeginStreaming(URL);
        }
        //OnResume Method check if streaming is suspending and continue with the streaming
        protected override void OnResume()
        {
            base.OnResume();
            if (mv != null)
            {
                if (suspending)
                {
                    BeginStreaming(URL);
                    suspending = false;
                }
            }
        }
        //OnDestroy Free Memory of a streaming
        protected override void OnDestroy()
        {
            base.OnDestroy();
            if (mv != null)
            {
                mv.FreeCameraMemory();
            }
        }
        //OnPause put the streaming suspending
        protected override void OnPause()
        {
            base.OnPause();
            if (mv != null)
            {
                if (mv.IsStreaming)
                {
                    mv.StopPlayback();
                    suspending = true;
                }
            }
        }
        /// <summary>
        /// Begins the streaming.
        /// with a parallel task we start the streaming
        /// </summary>
        /// <param name="url">URL.
        public void BeginStreaming(string url)
        {
            //Create a new task with a MjpegInputStream return
            Task.Factory.StartNew(() =>
            {
                try
                {
                    //inicialize streaming
                    return MjpegInputStream.Read(url);
                }
                catch (Exception e)
                {
                    //if something was wrong return null
                    Console.WriteLine(e.Message);
                }
                return null;
            }).ContinueWith((t) =>
            {
                //check if the result was fine
                mv.SetSource(t.Result);
                if (t.Result != null)
                {
                    //set skip to result
                    t.Result.SetSkip(1);
                    Title = "Connected";
                }
                else
                {
                    Title = "Disconnected";
                }
                //set display mode
                mv.SetDisplayMode(MjpegView.SizeFullscreen);
                //set if you need to see FPS
                mv.ShowFps(false);
            });
        }
    }
}

和Main.axml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/editText1"
        android:text="http://webcam.st-malo.com/axis-cgi/mjpg/video.cgi?resolution=640x480" />
    <Button
        android:id="@+id/myButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="watch" />

    <com.camera.simplemjpeg.MjpegView
        android:id="@+id/mv"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1" />

</LinearLayout>

感谢您的回答!

1 个答案:

答案 0 :(得分:0)

好吧,确保对该jar文件的构建操作设置在“Embeddedjar”上。如果您还没有安装JDK 1.8,请安装它。这帮我解决了这个错误。不幸的是,我仍然遇到播放流的问题。也许你会有更好的运气.-。