private VideoSource VideoSourceFromType(string videoSource, VideoType videoType) { VideoSource source = null; if (videoType == VideoType.YouTube) { source = YouTubeVideoSourceConstructor(videoSource); } else if (videoType == VideoType.Url) { source = VideoSource.FromUri(videoSource); } else if (videoType == VideoType.Resource) { source = VideoSource.FromResource(videoSource, resourceAssembly); } else if (videoType == VideoType.File) { source = VideoSource.FromFile(videoSource); } return(source); }
public MainPage() { InitializeComponent(); VideoPlayer.Source = MarkupExtensions.YouTubeVideoIdExtension.Convert("Q8-_F8aQNa0"); takePhoto.Clicked += async(sender, args) => { if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) { DisplayAlert("No Camera", ":( No camera available.", "OK"); return; } var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { Directory = "Test", SaveToAlbum = true, CompressionQuality = 75, CustomPhotoSize = 50, PhotoSize = PhotoSize.MaxWidthHeight, MaxWidthHeight = 2000, DefaultCamera = CameraDevice.Front }); if (file == null) { return; } DisplayAlert("File Location", file.Path, "OK"); image.Source = ImageSource.FromStream(() => { var stream = file.GetStream(); file.Dispose(); return(stream); }); }; pickPhoto.Clicked += async(sender, args) => { if (!CrossMedia.Current.IsPickPhotoSupported) { DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK"); return; } var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions { PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium, }); if (file == null) { return; } image.Source = ImageSource.FromStream(() => { var stream = file.GetStream(); file.Dispose(); return(stream); }); }; takeVideo.Clicked += async(sender, args) => { if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakeVideoSupported) { DisplayAlert("No Camera", ":( No camera avaialble.", "OK"); return; } var file = await CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions { Name = "video.mp4", Directory = "DefaultVideos", }); if (file == null) { return; } DisplayAlert("Video Recorded", "Location: " + file.Path, "OK"); VideoPlayer.Source = VideoSource.FromFile(file.Path); file.Dispose(); }; pickVideo.Clicked += async(sender, args) => { if (!CrossMedia.Current.IsPickVideoSupported) { DisplayAlert("Videos Not Supported", ":( Permission not granted to videos.", "OK"); return; } var file = await CrossMedia.Current.PickVideoAsync(); if (file == null) { return; } DisplayAlert("Video Selected", "Location: " + file.Path, "OK"); VideoPlayer.Source = VideoSource.FromFile(file.Path); file.Dispose(); }; }