gpt4 book ai didi

c# - Xamarin - MediaPicker 不显示适用于 iOS 的 videoPicker

转载 作者:行者123 更新时间:2023-11-28 22:02:37 28 4
gpt4 key购买 nike

我尝试在我正在编写的主应用程序中执行此操作,但似乎无法使其正常工作。所以我创建了一个单 View 应用程序来尝试并找出它,但我似乎仍然被卡住了。他就是我得到的。

public partial class HelloViewController : UIViewController
{
partial class VideoPickerController : UIViewController
{
MediaPicker videoPicker;
readonly TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
public VideoPickerController (IntPtr handle) : base (handle)
{
}

public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();

// Release any cached data, images, etc that aren't in use.
}

public override void ViewDidLoad ()
{
base.ViewDidLoad ();

var picker = new MediaPicker ();

PresentViewController (picker.GetPickPhotoUI (), true, null);


}
}
}

基本上我得到的只是一个白屏,没有任何反应。谢谢!

最佳答案

我认为您不需要手动呈现它。这是我使用的代码,它会自动为我呈现 UI。这段代码不在它自己的 View Controller 中,它只是在我有按钮拍照的任何 View Controller 中。相册和拍视频也有类似的方法。

Here是指向我托管此示例应用程序的 github 页面的链接。

var picker = new Xamarin.Media.MediaPicker();

btnCamera.Hidden = !picker.IsCameraAvailable;
btnCamera.TouchUpInside += async (sender, e) =>
{
try
{
MediaFile file =
await picker.TakePhotoAsync(new StoreCameraMediaOptions());
processImage(file);
}
catch { }
};

btnPhoto.Hidden = !picker.PhotosSupported;
btnPhoto.TouchUpInside += async (sender, e) =>
{
try
{
MediaFile file = await picker.PickPhotoAsync();
processImage(file);
}
catch { }
};

private void processImage(MediaFile file)
{
if (file != null)
{
viewModel.Image = file.GetStream();
viewModel.ImagePath = file.Path;
setImage();
}
}

private void setImage()
{
try
{
System.Diagnostics.Debug.WriteLine(viewModel.ImagePath);
if (!string.IsNullOrEmpty(viewModel.ImagePath) &&
System.IO.File.Exists(viewModel.ImagePath))
{
imgImage.Image = new UIImage(NSData.FromFile(viewModel.ImagePath));
}
else if (viewModel.Image != null && viewModel.Image.Length != 0)
{
imgImage.Image = new UIImage(NSData.FromStream(viewModel.Image));
}
}
//just don't load image
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}

关于c# - Xamarin - MediaPicker 不显示适用于 iOS 的 videoPicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24769808/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com