public override void OnConfigureFailed(CameraCaptureSession session) { if (null != fragment.Activity) { LoginFuncs.ShowToast(fragment.Activity, new Exception("Failed to open camera")); } //Toast.MakeText(fragment.Activity, "Failed", ToastLength.Short).Show(); }
private async void PlayEdit(Edit edit) { var videofile = edit.shortlink; shareedit = edit; Bootlegger.BootleggerClient.LogUserAction("Preview", new KeyValuePair <string, string>("editid", edit.id)); //AndHUD.Shared.Show(this, "Loading...", -1, MaskType.Black, null, null, true); //FindViewById<EditVideoView>(Resource.Id.videoplayer).ClearVideoSource(); //FindViewById<ImageButton>(Resource.Id.sharebtn).Visibility = ViewStates.Visible; //get video url: try { //set other fields: FindViewById <TextView>(Resource.Id.metadata).Text = edit.title; FindViewById <TextView>(Resource.Id.timemeta).Text = edit.createdAt.LocalizeFormat("ha E d MMM yy"); if (string.IsNullOrEmpty(edit.description)) { FindViewById <TextView>(Resource.Id.description).Visibility = ViewStates.Gone; } else { FindViewById <TextView>(Resource.Id.description).Text = edit.description; FindViewById <TextView>(Resource.Id.description).Visibility = ViewStates.Visible; } string url = await Bootlegger.BootleggerClient.GetEditUrl(edit); //DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory("BootleggerPreview"); ////var ok = new OkHttpClient(); //int cacheSize = 300 * 1024 * 1024; // 300 MiB //Square.OkHttp3.Cache cache = new Square.OkHttp3.Cache(FilesDir, cacheSize); var client = new OkHttpClient.Builder() //.Cache((Application as BootleggerApp).FilesCache) .Build(); OkHttpDataSourceFactory httpDataSourceFactory = new OkHttpDataSourceFactory(client, "BootleggerPreview"); var extractorsFactory = new DefaultExtractorsFactory(); mediaSource = new ExtractorMediaSource(Android.Net.Uri.Parse(url), httpDataSourceFactory, extractorsFactory, null, null); _player.Prepare(mediaSource); } catch (Exception e) { //adjust to what kind of exception it is: LoginFuncs.ShowToast(this, e); } finally { //AndHUD.Shared.Dismiss(); } }
private void StartPlayback() { TRIMMODE = false; _adapter.UpdatePlaying(null); _adapter.TrimMode(null, false); TrimOff(); FindViewById(Resource.Id.edittimeline).Visibility = ViewStates.Visible; //FindViewById(Resource.Id.pausebtn).Visibility = ViewStates.Invisible; if (CurrentEdit.media.Count == 1) { return; } //play current index: if (play_index < 0) { play_index = 0; } if (play_index > CurrentEdit.media.Count - 2) { play_index = CurrentEdit.media.Count - 2; } current_media = CurrentEdit.media[play_index]; try { preview.PlaySequence(CurrentEdit.media, current_media); } catch (Exception e) { //Toast.MakeText(this, e.Message, ToastLength.Short).Show(); LoginFuncs.ShowToast(this, e); } Bootlegger.BootleggerClient.LogUserAction("EditScreenPlaySeq", new KeyValuePair <string, string>("mediaid", current_media.id), new KeyValuePair <string, string>("editid", CurrentEdit.id), new KeyValuePair <string, string>("eventid", Bootlegger.BootleggerClient.CurrentEvent.id)); }
private void _adapter_OnTrim(MediaItem obj) { if (!TRIMMODE) { TRIMMODE = true; _adapter.TrimMode(obj, true); _adapter.UpdatePlaying(obj); //open in trim mode current_media = obj; play_index = CurrentEdit.media.IndexOf(current_media); FindViewById(Resource.Id.edittimeline).Visibility = ViewStates.Invisible; TrimOn(); try { preview.StopPlayback(); _adapter.UpdatePlaying(null); preview.TrimVideo(current_media); } catch (Exception e) { //Toast.MakeText(this, e.Message, ToastLength.Short).Show(); LoginFuncs.ShowToast(this, e); } Bootlegger.BootleggerClient.LogUserAction("EditScreenTrim", new KeyValuePair <string, string>("mediaid", current_media.id), new KeyValuePair <string, string>("editid", CurrentEdit.id), new KeyValuePair <string, string>("eventid", Bootlegger.BootleggerClient.CurrentEvent.id)); } else { preview.StopPlayback(); TRIMMODE = false; _adapter.UpdatePlaying(null); _adapter.TrimMode(null, false); TrimOff(); } }
public void ExitSave() { ShouldAutoSave = false; preview.StopPlayback(); _adapter.UpdatePlaying(null); if (!CurrentEdit.media.Any(n => n.MediaType != Shot.ShotTypes.TITLE && n.Status != MediaItem.MediaStatus.PLACEHOLDER)) { Toast.MakeText(this, Resource.String.includevideo, ToastLength.Long).Show(); ShouldAutoSave = true; return; } Android.Support.V7.App.AlertDialog.Builder builder = new Android.Support.V7.App.AlertDialog.Builder(this); FrameLayout frameView = new FrameLayout(this); builder.SetView(frameView); var diag = builder.Create(); diag.SetTitle(Resource.String.saveedit); LayoutInflater inflater = diag.LayoutInflater; View dialoglayout = inflater.Inflate(Resource.Layout.editsavedlg, frameView); //set title of video if there is one: if (string.IsNullOrWhiteSpace(CurrentEdit.title)) { if (CurrentEdit.media.First().MediaType == Shot.ShotTypes.TITLE) { CurrentEdit.title = CurrentEdit.media.First().titletext; } } //adjust for audio: if (CurrentMusic != null) { foreach (var m in CurrentEdit.media) { m.audio = null; m.credits = null; } CurrentEdit.media.First().audio = CurrentMusic.path; CurrentEdit.media.First().credits = CurrentMusic.caption; } dialoglayout.FindViewById <TextView>(Resource.Id.title).Text = CurrentEdit.title; if (WhiteLabelConfig.USE_EDIT_DESCRIPTION) { dialoglayout.FindViewById <TextView>(Resource.Id.description).Text = CurrentEdit.description; } else { dialoglayout.FindViewById <TextView>(Resource.Id.description).Visibility = ViewStates.Gone; } dialoglayout.FindViewById <Button>(Resource.Id.savebtn).Click += async(o, e) => { bool doit = true; if (dialoglayout.FindViewById <TextView>(Resource.Id.title).Text.Length < 5) { TextInputLayout titlelayout = dialoglayout.FindViewById <TextInputLayout>(Resource.Id.title_layout); titlelayout.ErrorEnabled = true; titlelayout.Error = Resources.GetString(Resource.String.entertitle); doit = false; } if (WhiteLabelConfig.USE_EDIT_DESCRIPTION) { if (dialoglayout.FindViewById <TextView>(Resource.Id.description).Text.Length < 5) { TextInputLayout titlelayout = dialoglayout.FindViewById <TextInputLayout>(Resource.Id.description_layout); titlelayout.ErrorEnabled = true; titlelayout.Error = Resources.GetString(Resource.String.enterdescription); doit = false; } } if (doit) { CurrentEdit.title = dialoglayout.FindViewById <TextView>(Resource.Id.title).Text; CurrentEdit.description = dialoglayout.FindViewById <TextView>(Resource.Id.description).Text; AndHUD.Shared.Show(this, Resources.GetString(Resource.String.loading), -1, MaskType.Black, null, null, true); try { await Bootlegger.BootleggerClient.SaveEdit(CurrentEdit); Intent i = new Intent(this.ApplicationContext, typeof(Review)); i.PutExtra("processed", true); StartActivity(i); Finish(); } catch (Exception ex) { _adapter.UpdateData(CurrentEdit.media); _sliveradapter.UpdateData(CurrentEdit.media); UpdateTimings(); //Toast.MakeText(this, Resources.GetString(Resource.String.editerror), ToastLength.Long).Show(); LoginFuncs.ShowToast(this, ex); } finally { AndHUD.Shared.Dismiss(); diag.Cancel(); } } }; dialoglayout.FindViewById <Button>(Resource.Id.sharebtn).Click += async(o, e) => { bool doit = true; if (dialoglayout.FindViewById <TextView>(Resource.Id.title).Text.Length < 5) { TextInputLayout titlelayout = dialoglayout.FindViewById <TextInputLayout>(Resource.Id.title_layout); titlelayout.ErrorEnabled = true; titlelayout.Error = Resources.GetString(Resource.String.entertitle); doit = false; } if (WhiteLabelConfig.USE_EDIT_DESCRIPTION) { if (dialoglayout.FindViewById <TextView>(Resource.Id.description).Text.Length < 5) { TextInputLayout titlelayout = dialoglayout.FindViewById <TextInputLayout>(Resource.Id.description_layout); titlelayout.ErrorEnabled = true; titlelayout.Error = Resources.GetString(Resource.String.enterdescription); doit = false; } } if (doit) { CurrentEdit.title = dialoglayout.FindViewById <TextView>(Resource.Id.title).Text; CurrentEdit.description = dialoglayout.FindViewById <TextView>(Resource.Id.description).Text; AndHUD.Shared.Show(this, Resources.GetString(Resource.String.loading), -1, MaskType.Black, null, null, true); try { await Bootlegger.BootleggerClient.StartEdit(CurrentEdit); Bundle conData = new Bundle(); conData.PutBoolean("processed", true); Intent intent = new Intent(); intent.PutExtras(conData); SetResult(Result.Ok, intent); Intent i = new Intent(this.ApplicationContext, typeof(Review)); StartActivity(i); } catch (Exception ex) { _adapter.UpdateData(CurrentEdit.media); _sliveradapter.UpdateData(CurrentEdit.media); UpdateTimings(); LoginFuncs.ShowToast(this, ex); } finally { AndHUD.Shared.Dismiss(); diag.Cancel(); } } }; diag.SetCancelable(true); diag.CancelEvent += (o, e) => { ShouldAutoSave = true; }; diag.Show(); dialoglayout.Post(() => { dialoglayout.FindViewById <TextView>(Resource.Id.title).RequestFocus(); }); }
//private void Preview_Click(object sender, EventArgs e) //{ // Intent sharingIntent = new Intent(Intent.ActionSend); // sharingIntent.SetType("text/plain"); // sharingIntent.PutExtra(Intent.ExtraSubject, shareedit.title); // sharingIntent.PutExtra(Intent.ExtraText, Bootlegger.BootleggerClient.server + "/v/" + shareedit.shortlink); // StartActivity(Intent.CreateChooser(sharingIntent, new Java.Lang.String(Resources.GetString(Resource.String.sharevia)))); //} public async void PlayVideo(MediaItem media) { Bootlegger.BootleggerClient.LogUserAction("Preview", new KeyValuePair <string, string>("mediaid", media.id)); if (Intent.GetBooleanExtra(Review.INGEST_MODE, false)) { var rv = FindViewById <RecyclerView>(Resource.Id.list); rv.SetLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.Horizontal, false)); var _readonly = Intent.GetBooleanExtra(Review.READ_ONLY, false); var chips = new ChipAdapter(this, _readonly); //var prev = Resources.GetStringArray(Resource.Array.default_edit_topics).ToList(); //if (string.IsNullOrEmpty(Bootlegger.BootleggerClient.CurrentEvent.topics)) // Bootlegger.BootleggerClient.CurrentEvent.topics = string.Join(",", prev); //else //prev = Bootlegger.BootleggerClient.CurrentEvent.topics.Split(',').ToList(); if (_readonly) { chips.Update(null, media); } else { chips.Update(Bootlegger.BootleggerClient.CurrentEvent.topics.ToList(), media); } rv.SetAdapter(chips); FindViewById(Resource.Id.videometadata).Visibility = ViewStates.Gone; } FindViewById <ImageView>(Resource.Id.imageplayer).SetImageDrawable(null); try { FindViewById <TextView>(Resource.Id.metadata).Text = media.meta.shot_ex["name"].ToString() + " at " + media.meta.role_ex["name"].ToString() + " during " + media.meta.phase_ex["name"].ToString(); } catch { FindViewById <TextView>(Resource.Id.metadata).Text = ""; } try { FindViewById <TextView>(Resource.Id.timemeta).Text = media.CreatedAt.LocalizeFormat("ha E d MMM yy"); } catch { FindViewById <TextView>(Resource.Id.timemeta).Text = media.Static_Meta["captured_at"].ToString(); } FindViewById <TextView>(Resource.Id.description).Visibility = ViewStates.Gone; switch (media.MediaType) { case Shot.ShotTypes.VIDEO: case Shot.ShotTypes.AUDIO: //FindViewById<View>(Resource.Id.videoplayer).Visibility = ViewStates.Visible; try { //set other fields: string url = await Bootlegger.BootleggerClient.GetVideoUrl(media); if (url.StartsWith("file://")) { DefaultDataSourceFactory httpDataSourceFactory = new DefaultDataSourceFactory(this, "BootleggerPreview"); var extractorsFactory = new DefaultExtractorsFactory(); mediaSource = new ExtractorMediaSource(Android.Net.Uri.Parse(url), httpDataSourceFactory, extractorsFactory, null, null); } else { var client = new OkHttpClient.Builder() .Cache((Application as BootleggerApp).FilesCache) .Build(); OkHttpDataSourceFactory httpDataSourceFactory = new OkHttpDataSourceFactory(client, "BootleggerPreview"); var extractorsFactory = new DefaultExtractorsFactory(); mediaSource = new ExtractorMediaSource(Android.Net.Uri.Parse(url), httpDataSourceFactory, extractorsFactory, null, null); } _player.Prepare(mediaSource); } catch (Exception e) { //Toast.MakeText(this, Resource.String.cannotloadvideo, ToastLength.Short).Show(); LoginFuncs.ShowToast(this, e); } break; case Shot.ShotTypes.PHOTO: //FindViewById<View>(Resource.Id.videoplayer).Visibility = ViewStates.Gone; if (media.Status == MediaItem.MediaStatus.DONE && !string.IsNullOrEmpty(media.path)) { //string url = await (Application as BootleggerApp).Comms.(videofile); Picasso.With(this).Load(media.Thumb + "?s=300").Fit().CenterInside().Into(FindViewById <ImageView>(Resource.Id.imageplayer)); } else { Picasso.With(this).Load("file://" + media.Filename).Fit().CenterInside().Into(FindViewById <ImageView>(Resource.Id.imageplayer)); } break; } }
void IPlayerEventListener.OnPlayerError(ExoPlaybackException p0) { LoginFuncs.ShowToast(Context, p0); //Toast.MakeText(Context, Resource.String.noconnectionshort, ToastLength.Short).Show(); }
public async void TrimVideo(MediaItem meta) { //fade out current... FindViewById(Resource.Id.trackcontrols).Visibility = ViewStates.Visible; FindViewById <View>(Resource.Id.progress).Visibility = ViewStates.Visible; _playerView.Visibility = ViewStates.Visible; //_audioPlayer.Volume = 0; _audioPlayer.PlayWhenReady = false; try { var uri = await Bootlegger.BootleggerClient.GetVideoUrl(meta); currentitem = meta; //Console.WriteLine("ci ip: " + meta.inpoint); currentmode = PLAYBACK_MODE.TRIM_CLIP; switch (currentitem?.MediaType ?? Shot.ShotTypes.VIDEO) { case Shot.ShotTypes.VIDEO: case Shot.ShotTypes.AUDIO: PrepareSingleSource(uri, meta); _player.PlayWhenReady = false; _player.SeekTo((long)currentitem.inpoint.TotalMilliseconds); _player.PlayWhenReady = true; _player.RepeatMode = Player.RepeatModeOne; break; case Shot.ShotTypes.TITLE: try { _player.Prepare(mediaSource); } catch (Exception e) { //Toast.MakeText(Context, Resource.String.noconnectionshort, ToastLength.Short).Show(); LoginFuncs.ShowToast(Context, e); //LoginFuncs.ShowError(Context, new Exception(e.Message)); } break; } seeker.Visibility = ViewStates.Invisible; //Console.WriteLine(uri); _playerView.Post(() => { //video.Start(); //FindViewById<ImageView>(Resource.Id.pausebtn).Visibility = ViewStates.Gone; try { if (WhiteLabelConfig.SHOW_META_EDITING) { if (meta != null) { FindViewById <TextView>(Resource.Id.username).Text = meta.Contributor.ToString(); FindViewById <TextView>(Resource.Id.role).Text = meta.meta.role_ex["name"].ToString(); FindViewById <TextView>(Resource.Id.phase).Text = meta.meta.phase_ex["name"].ToString(); FindViewById <TextView>(Resource.Id.shot).Text = meta.meta.shot_ex["name"].ToString(); } else { FindViewById <TextView>(Resource.Id.username).Text = "unknown"; FindViewById <TextView>(Resource.Id.role).Text = "unknown"; FindViewById <TextView>(Resource.Id.phase).Text = "unknown"; FindViewById <TextView>(Resource.Id.shot).Text = "unknown"; } } } catch { } }); source = uri; } catch (Exception e) { LoginFuncs.ShowError(Context, e); } }
public async void PlaySequence(List <MediaItem> meta, MediaItem startingat) { currentsequence = meta; currentmode = PLAYBACK_MODE.PLAY_EDIT; _playerView.Visibility = ViewStates.Visible; FindViewById(Resource.Id.trackcontrols).Visibility = ViewStates.Invisible; FindViewById <View>(Resource.Id.progress).Visibility = ViewStates.Visible; //build media source: DynamicConcatenatingMediaSource source = new DynamicConcatenatingMediaSource(); foreach (var m in meta.GetRange(0, meta.Count - 1)) { if (m.MediaType == Shot.ShotTypes.TITLE) { //var textn = m.titletext.Split('\n'); //var titletext = System.Uri.EscapeDataString(m.titletext.TrimStart('\n')); //var titletext = URLEncoder.Encode(m.titletext.TrimStart('\n'),"utf-8"); var titletext = m.titletext.TrimStart('\n'); //var numlines = titletext.Split('\n').Length; //line:-{4-numlines} //string text = URLEncoder.Encode($"WEBVTT\n\n00:00.000 --> 00:{m.outpoint.Seconds.ToString("D2")}.000\n{titletext}", "utf-8"); string text = $"WEBVTT\n\n00:00.000 --> 00:{m.outpoint.Seconds.ToString("D2")}.000\n{titletext}"; Format textFormat = Format.CreateTextSampleFormat(null, MimeTypes.TextVtt, Format.NoValue, "en"); var mm = new MergingMediaSource( new ExtractorMediaSource(Android.Net.Uri.Parse("rawresource:///" + Resource.Raw.blackvideo), defaultDataSourceFactory, extractorsFactory, null, null), new SingleSampleMediaSource(Android.Net.Uri.Parse("data:text/vtt," + text), defaultDataSourceFactory, textFormat, (long)m.outpoint.TotalMilliseconds) ); source.AddMediaSource(mm); } else { try { var uri = await Bootlegger.BootleggerClient.GetVideoUrl(m); ExtractorMediaSource ss; if (uri.StartsWith("file://")) { ss = new ExtractorMediaSource(Android.Net.Uri.Parse(uri), defaultDataSourceFactory, extractorsFactory, null, null); } else { ss = new ExtractorMediaSource(Android.Net.Uri.Parse(uri), httpDataSourceFactory, extractorsFactory, null, null); } var mm = new ClippingMediaSource(ss, (long)m.inpoint.TotalMilliseconds * 1000, (long)m.outpoint.TotalMilliseconds * 1000); source.AddMediaSource(mm); } catch (Exception e) { LoginFuncs.ShowToast(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity, e); //Toast.MakeText(Context, Resource.String.noconnectionshort, ToastLength.Short).Show(); } } } mediaSource = source; try { _player.Prepare(mediaSource); _player.PlayWhenReady = true; _player.RepeatMode = Player.RepeatModeAll; //seek to start of the chosen clip: _player.SeekTo(meta.IndexOf(startingat), 0); if (audioSource != null) { //seek audio: _audioPlayer.SeekTo((long)CountToIndex(meta, startingat)); } //throw new Exception("THIS BREAKS DATABASE"); } catch (Exception e) { Console.WriteLine(e); //Toast.MakeText(Context, Resource.String.noconnectionshort, ToastLength.Short).Show(); LoginFuncs.ShowToast(Context, e); //LoginFuncs.ShowError(Context, e); } }
private async void ViewHolder_Select(object sender, CheckedChangeEventArgs e) { if (adpt.media != null) { try { var key = $"{((!WhiteLabelConfig.PUBLIC_TOPICS) ? BootleggerClient.CurrentUser?.id : "")}-{MetaDataFields.Topics}"; if (!adpt.media.Static_Meta.ContainsKey(key)) { adpt.media.Static_Meta[key] = ""; } var mt = adpt.media.Static_Meta[key].Split(',').ToList(); if (e.IsChecked) { mt.Add(currentitem.id); } else { mt.Remove(currentitem.id); } //remove blanks mt.RemoveAll((n) => string.IsNullOrEmpty(n)); if (mt.Count > 0) { adpt.media.Static_Meta[$"{((!WhiteLabelConfig.PUBLIC_TOPICS) ? BootleggerClient.CurrentUser?.id : "")}-{MetaDataFields.Topics}"] = string.Join(",", mt); } else { adpt.media.Static_Meta.Remove($"{((!WhiteLabelConfig.PUBLIC_TOPICS) ? BootleggerClient.CurrentUser?.id : "")}-{MetaDataFields.Topics}"); } BootleggerClient.SaveMedia(adpt.media); await BootleggerClient.UpdateMeta(adpt.media); if (e.IsChecked && !adpt._readonly) { view.FindViewById <ToggleButton>(Resource.Id.chip).SetCompoundDrawablesWithIntrinsicBounds(0, 0, Resource.Drawable.baseline_check_white_24, 0); } else { view.FindViewById <ToggleButton>(Resource.Id.chip).SetCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); } } catch (Exception ex) { //failed LoginFuncs.ShowToast(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity, ex); //Toast.MakeText(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity, Resource.String.noconnectionshort, ToastLength.Short).Show(); } } else { if (e.IsChecked && !adpt._readonly) { view.FindViewById <ToggleButton>(Resource.Id.chip).SetCompoundDrawablesWithIntrinsicBounds(0, 0, Resource.Drawable.baseline_check_white_24, 0); } else { view.FindViewById <ToggleButton>(Resource.Id.chip).SetCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); } adpt.FireFilterUpdate(currentitem); } }