当前上下文C#错误中不存在名称“CrossMedia”

时间:2017-04-06 20:30:26

标签: c# android xamarin media

我正在为Xamarin Studio编写媒体插件的代码,显然我在尝试构建应用时出现以下错误:

“当前上下文中不存在'CrossMedia'这个名称”

我一直试图找到解决问题的方法。下面是代码。

using System;
using Relate.Model;
using Xamarin.Forms;

using System.IO;

namespace Relate.Views
{

    public partial class EditMemberPage : ContentPage
    {
        public EditMemberPage()
        {
            InitializeComponent();
        }

        async void TakeaPhoto_OnClicked(object sender, EventArgs e)
        {

          if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
            {
                // Supply media options for saving our photo after it's taken.
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Receipts",
                    Name = $"{DateTime.UtcNow}.jpg"
                };

                // Take a photo of the business receipt.
                var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);
            }

            if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakeVideoSupported)
            {
                // Supply media options for saving our video after it's taken.
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Videos",
                    Name = $"{DateTime.UtcNow}.mp4"
                };

                // Record a video
                var file = await CrossMedia.Current.TakeVideoAsync(mediaOptions);
            }

            // Select a photo. 
            if (CrossMedia.Current.IsPickPhotoSupported)
            {
                var photo = await CrossMedia.Current.PickPhotoAsync();
            }

            // Select a video. 
            if (CrossMedia.Current.IsPickVideoSupported)
            {
                var video = await CrossMedia.Current.PickVideoAsync();
            }
        }

        async void SaveButton_OnClicked(object sender, EventArgs e)
        {
            var famMemberItem = (FamMember)BindingContext;
            await App.Database.SaveFamMemberAsync(famMemberItem);
            await Navigation.PopAsync();
        }
    }
}

2 个答案:

答案 0 :(得分:0)

using Plugin.Media;添加到文件的开头

答案 1 :(得分:0)

首先尝试初始化插件,然后再使用它,如文档中所述。

await CrossMedia.Current.Initialize();