Exemplo n.º 1
0
        async Task <List <MediaInfoDto> > genPlayListFromFile(MediaInfoDto mid)
        {
            var lst = new List <MediaInfoDto>();

            try
            {
                foreach (var file in Directory.EnumerateFiles(mid.PathOnly, "*.*", SearchOption.TopDirectoryOnly).ToList().OrderBy(r => r))
                {
                    var sf = await StorageFile.GetFileFromPathAsync(file); //sep13

                    var mid2 = new MediaInfoDto(sf);                       //sep13
                    await mid2.SetThumbnail(sf);                           //sep13

                    lst.Add(mid2);                                         //org: PLsLst.Add(new MediaInfoDto(await StorageFile.GetFileFromPathAsync(file)));
                }

                SlctLib = lst.FirstOrDefault(r => r.FileOnly.Equals(mid.FileOnly, StringComparison.OrdinalIgnoreCase));

                //savePlt();
            }
            catch (Exception ex) { Debug.WriteLine($"$#~>{ex.Message}"); if (Debugger.IsAttached)
                                   {
                                       Debugger.Break();
                                   }
                                   else
                                   {
                                       await popEx(ex, GetType().FullName);
                                   } }

            return(lst);
        }
Exemplo n.º 2
0
        async void addUpdateSave_Mru(MediaInfoDto mid)
        {
            try
            {
                if (!_mrulst.Any(r => r.FileOnly.Equals(mid.FileOnly, StringComparison.OrdinalIgnoreCase)))
                {
                    _mrulst.Add(mid);
                }
                else
                {
                    var mru = _mrulst.FirstOrDefault(r => r.FileOnly.Equals(mid.FileOnly, StringComparison.OrdinalIgnoreCase));
                    if (mru.LastPcNm != DevOp.MachineName)
                    {
                        mru.LastPcNm = DevOp.MachineName;
                    }
                    else
                    {
                        return;
                    }
                }

                saveMru();
            }
            catch (Exception ex) { Debug.WriteLine($"$#~>{ex.Message}"); if (Debugger.IsAttached)
                                   {
                                       Debugger.Break();
                                   }
                                   else
                                   {
                                       await popEx(ex, GetType().FullName);
                                   } }
        }
Exemplo n.º 3
0
        public async Task <bool> MidExists(MediaInfoDto mid)
        {
            bool exists = false;

            try
            {
                var sf = await StorageFile.GetFileFromPathAsync(mid.PathFile);

                if (sf != null)
                {
                    exists = true;
                }
            }
            catch (UnauthorizedAccessException) { return(false); }
            catch (FileNotFoundException) { return(false); }
            catch (Exception ex) { Debug.WriteLine($"$#~>{ex.Message}"); if (Debugger.IsAttached)
                                   {
                                       Debugger.Break();
                                   }
                                   else
                                   {
                                       await popEx(ex, mid.PathFile);
                                   } }
            finally
            {
                //mid.MuExists
                //mid.PcBrush = exists ?
                //  new SolidColorBrush(Color.FromArgb(255, 0, 255, 0)) :
                //  new SolidColorBrush(Color.FromArgb(255, 0, 128, 128));
            }

            return(exists);
        }
Exemplo n.º 4
0
        async Task addNewOrFromMru(StorageFile sf)
        {
            var sz = (await sf.GetBasicPropertiesAsync()).Size;

            if (sz > 10000) // 500,000 <== a typical pod.anons is 200k ==> anything below 10k is corrupt.
            {
                var fsMid = new MediaInfoDto(sf);
                var liMid = LibLst.FirstOrDefault(r => r.FileOnly.Equals(fsMid.FileOnly, StringComparison.OrdinalIgnoreCase));
                if (liMid != null) // already in the Lib list
                {
                    return;
                }

                var mrMid = MruLst.FirstOrDefault(r => r.FileOnly.Equals(fsMid.FileOnly, StringComparison.OrdinalIgnoreCase));
                if (mrMid != null)
                {
                    await mrMid.SetThumbnail(sf);

                    LibLst.Add(mrMid);
                }
                else
                {
                    await fsMid.SetThumbnail(sf);

                    LibLst.Add(fsMid);
                }
            }
            else
            {
                Debug.WriteLine($"{sf.DisplayName}\t Too tiny to add: {(sz * .001):N0} kb ");
            }
        }
Exemplo n.º 5
0
        async Task loadPlay(StorageFile storageFile)
        {
            if (storageFile == null)
            {
                return;
            }

            tbInfo.Text += $"\r\n{storageFile.Name}";

            ApplicationView.GetForCurrentView().Title = storageFile.Name;

            var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

            me_Xm.SetSource(stream, storageFile.ContentType);

            var sval = (string)AppSettingsHelper.ReadVal(storageFile.Name);

            if (sval != null)
            {
                _mid = JsonHelper.FromJson <MediaInfoDto>(sval);
                if (_mid.FileOnly != null)
                {
                    //nogo: not loaded yet: if (mid.PlayPosn.TotalSeconds > 15) me1.Position = mid.PlayPosn;

                    me_Xm.Play(); //? does it work?
                    return;
                }
            }

            _mid = new MediaInfoDto(storageFile);

            AppSettingsHelper.SaveVal(_mid.FileOnly, JsonHelper.ToJson(_mid));

            me_Xm.Play(); //? does it work?
        }
Exemplo n.º 6
0
        async Task setNext(MediaInfoDto mid)
        {
            await addToMruListIfNotThere(mid);

            //SlctPLs = PLsLst.FirstOrDefault(r => r.FileOnly.Equals(mid.FileOnly, StringComparison.OrdinalIgnoreCase));
            SlctMru = MruLst.FirstOrDefault(r => r.FileOnly.Equals(mid.FileOnly, StringComparison.OrdinalIgnoreCase));
            SlctLib = LibLst.FirstOrDefault(r => r.FileOnly.Equals(mid.FileOnly, StringComparison.OrdinalIgnoreCase));
        }
Exemplo n.º 7
0
        async Task addToMruListIfNotThere(MediaInfoDto nxtPLt)
        {
            if (!MruLst.Any(r => r.FileOnly.Equals(nxtPLt.FileOnly, StringComparison.OrdinalIgnoreCase)))
            {
                await nxtPLt.SetThumbnail(/*sf*/); //sep13

                MruLst.Add(nxtPLt);
            }
        }
Exemplo n.º 8
0
 async Task setPosnSafe(MediaInfoDto mid, string msg)
 {
     if (Dispatcher.HasThreadAccess)
     {
         setPosn(mid, msg);
     }
     else
     {
         await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => setPosn(mid, msg));
     }
 }
Exemplo n.º 9
0
        public void Mru_FindAdd_MakeCur(StorageFile sf)
        {
            if (MruLst.Any(r => sf.Name.Equals(r.FileOnly, StringComparison.OrdinalIgnoreCase)))
            {
                Cur = MruLst.First(r => sf.Name.Equals(r.FileOnly, StringComparison.OrdinalIgnoreCase));

                if (!Cur.PathFile.Equals(sf.Path, StringComparison.OrdinalIgnoreCase)) // if from another PC: update path to this one.
                {
                    Cur.PathFile = sf.Path;
                }
            }
            else
            {
                MruLst.Add((Cur = new MediaInfoDto(sf)
                {
                    LastUsed = DateTime.Now
                }));
            }
        }
Exemplo n.º 10
0
        async Task onDeleteDialog(MediaInfoDto mid)
        {
            var messageDialog = new MessageDialog($"Delete: {mid.PathFile}", "Are you sure?");

            messageDialog.Commands.Add(new UICommand("Yes", null, 0));
            messageDialog.Commands.Add(new UICommand("No", null, 1));
            messageDialog.DefaultCommandIndex = 1;  // Set the command that will be invoked by default
            messageDialog.CancelCommandIndex  = 1;  // Set the command to be invoked when escape is pressed

            var rv = await messageDialog.ShowAsync();

            if ((int)((UICommand)rv).Id != 0)
            {
                return;
            }

            await deleteCurMruMid(mid.PathFile);

            //? onRefreshList(sender, e);
        }
Exemplo n.º 11
0
        async Task <Tuple <bool, string> > trySetNextFromMru(MediaInfoDto mid)
        {
            if (MruLst.Count <= 1)
            {
                return(Tuple.Create(false, "Nothing to play in the MRU list"));
            }

            var nxtFromMru = MruLst.FirstOrDefault(r => !r.FileOnly.Equals(mid.FileOnly, StringComparison.OrdinalIgnoreCase));

            if (nxtFromMru == null)
            {
                return(Tuple.Create(false, "This is the last file in the MRU list."));
            }
            else
            {
                await setNext(nxtFromMru);

                return(Tuple.Create(true, ""));
            }
        }
Exemplo n.º 12
0
        async Task <Tuple <bool, string> > trySetNextFromDir(MediaInfoDto mid)
        {
            var curDirLst = await genPlayListFromFile(mid);

            if (curDirLst.Count <= 1)
            {
                return(Tuple.Create(false, "Nothing to play in the folder/playlist")); //if (Dispatcher.HasThreadAccess) Debug.WriteLine($"<><> Thread is OK <><>"); else await Speak($"WRONG Thread: non-UI! ");
            }
            var next = curDirLst.OrderBy(r => r.FileOnly).FirstOrDefault(r => !r.FileOnly.Equals(SlctMru.FileOnly, StringComparison.OrdinalIgnoreCase));

            if (next == null)
            {
                return(Tuple.Create(false, "This is the last of the playlist."));
            }
            else
            {
                TbInfo += ($" \r\n\r\n>>{SlctMru.NameOnly}\r\n>>{next.NameOnly}>>");
                Debug.WriteLine($"\r\n>>{SlctMru.NameOnly}\r\n>>{next.NameOnly}>>");

                await setNext(next);

                return(Tuple.Create(true, ""));
            }

            ////this works only for deleting listened mode:
            //var nxtFromPLs = PLsLst.FirstOrDefault(r => !r.FileOnly.Equals(mid.FileOnly, StringComparison.OrdinalIgnoreCase));
            //if (nxtFromPLs == null)
            //{
            //  return Tuple.Create(false, "This is the last file in the folder.");
            //}
            //else
            //{
            //  setNext(nxtFromPLs);
            //  return Tuple.Create(true, "");
            //}
        }
Exemplo n.º 13
0
 public void RemoveFromMruOnly(MediaInfoDto mid)
 {
     MruLst.Remove(mid);
 }
Exemplo n.º 14
0
        async void setPosn(MediaInfoDto mid, string msg)
        {
            while (mp_Vm.PlaybackSession.NaturalDuration == TimeSpan.Zero) /**/
            {
                await Task.Delay(44); Debug.WriteLine($"{mid.NameOnly,-22}\tSetPos -- No Duration yet. --");
            }

            if ((mp_Vm.PlaybackSession.NaturalDuration - mid.PlayPosn).TotalSeconds < 15)  // if practically at the end
            {
                mid.PlayPosn = TimeSpan.Zero;
                await Speak("Rewinded");
            }

            mp_Vm.PlaybackSession.Position = mid.PlayPosn;

            var s = $"{mid.NameOnly,-22}\tmdl:{mid.PlayPosn:h\\:mm\\:ss} plr:{mp_Vm.PlaybackSession.Position:h\\:mm\\:ss} drn:{mp_Vm.PlaybackSession.NaturalDuration:h\\:mm\\:ss}  {msg,-6}\t";

            Debug.WriteLine(s);
            TbInfo += $"\r\n{s}";

            if ((mid.PlayPosn - mp_Vm.PlaybackSession.Position).TotalSeconds > 0)
            {
                var p = $" ==unable to set position==";
                Debug.WriteLine(p);
                TbInfo += p;
                await Speak(p);
            }
        }

        async void startPlayingCurSelMid_void(MediaInfoDto mid) => await startPlayingCurSelMid_Task(mid);

        async Task startPlayingCurSelMid_Task(MediaInfoDto mid)
        {
            try
            {
                if (!await mid.FileExists())
                {
                    await Speak($"Removed since does not exist."); MruLst.Remove(mid); return;
                }

                var sf = await StorageFile.GetFileFromPathAsync(mid.PathFile); if (sf == null)
                {
                    await Speak($"Unable to GetFileFromPathAsync."); return;
                }

                mid.MuExists = "+++";
                mid.PcBrush  = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));

                await setCentralImageToThumbnail(sf);

                Debug.WriteLine($"{mid.NameOnly,-22}\t>>>Starting ");

                mp_Vm.Source = MediaSource.CreateFromStream(await sf.OpenAsync(FileAccessMode.Read), sf.ContentType); //
                mp_Vm.PlaybackSession.PlaybackRate = (double)(AppSettingsHelper.ReadVal(AppSetConst.PlayRate) ?? 1d);

                await setPosnSafe(mid, "Start");

                if (AppSettingsHelper.ReadVal(AppSetConst.PagesTtl) != null)
                {
                    PagesTtl = (uint)AppSettingsHelper.ReadVal(AppSetConst.PagesTtl);
                }
            }
            catch (Exception ex) { Debug.WriteLine($"$#~>{ex.Message}"); if (Debugger.IsAttached)
                                   {
                                       Debugger.Break();
                                   }
                                   else
                                   {
                                       await popEx(ex, GetType().FullName);
                                   } }
        }

        async Task setCentralImageToThumbnail(StorageFile sf)
        {
            await SlctMru.SetThumbnail(sf);

            if (SlctMru.Thumbnail != null)
            {
                _img1.Source = SlctMru.Thumbnail;
                //_img1.Width = 2 * SlctMru.Thumbnail.PixelWidth;
                //_img1.Height = 2 * SlctMru.Thumbnail.PixelHeight;
            }
        }

        void jump(double min = -.03)
        {
            if (min < 0)
            {
                if (mp_Vm.PlaybackSession.Position.TotalMinutes > -min)
                {
                    mp_Vm.PlaybackSession.Position = mp_Vm.PlaybackSession.Position + TimeSpan.FromMinutes(min);
                }
                else
                {
                    mp_Vm.PlaybackSession.Position = TimeSpan.Zero;
                }
            }
            else if (mp_Vm.PlaybackSession.NaturalDuration > mp_Vm.PlaybackSession.Position + TimeSpan.FromMinutes(min))
            {
                mp_Vm.PlaybackSession.Position = mp_Vm.PlaybackSession.Position + TimeSpan.FromMinutes(min);
            }
            else
            {
                mp_Vm.PlaybackSession.Position = mp_Vm.PlaybackSession.NaturalDuration - TimeSpan.FromSeconds(.1);
            }

            updateSaveSettings("j");
        }

        //    C:\gh\WUS2017\Samples\SystemMediaTransportControls\cs\Scenario1.xaml.cs
        SystemMediaTransportControls systemMediaControls = null;
        bool _isThisPageActive = true;
        //MediaPlaybackItem _mediaPlaybackItem;

        /// <summary>
        /// Invoked from this scenario page's OnNavigatedTo event handler.  Retrieve and initialize the SystemMediaTransportControls object.
        /// </summary>
        void SetupSystemMediaTransportControls()
        {
            // Retrieve the SystemMediaTransportControls object associated with the current app view
            // (ie. window).  There is exactly one instance of the object per view, instantiated by
            // the system the first time GetForCurrentView() is called for the view.  All subsequent
            // calls to GetForCurrentView() from the same view (eg. from different scenario pages in
            // this sample) will return the same instance of the object.
            systemMediaControls = SystemMediaTransportControls.GetForCurrentView();

            // This scenario will always start off with no media loaded, so we will start off disabling the
            // system media transport controls.  Doing so will hide the system UI for media transport controls
            // from being displayed, and will prevent the app from receiving any events such as ButtonPressed
            // from it, regardless of the current state of event registrations and button enable/disable states.
            // This makes IsEnabled a handy way to turn system media transport controls off and back on, as you
            // may want to do when the user navigates to and away from certain parts of your app.
            //systemMediaControls.IsEnabled = false;
            systemMediaControls.IsEnabled = true; //Nov 2017 - what if restore to false?

            // To receive notifications for the user pressing media keys (eg. "Stop") on the keyboard, or
            // clicking/tapping on the equivalent software buttons in the system media transport controls UI,
            // all of the following needs to be true:
            //     1. Register for ButtonPressed event on the SystemMediaTransportControls object.
            //     2. IsEnabled property must be true to enable SystemMediaTransportControls itself.
            //        [Note: IsEnabled is initialized to true when the system instantiates the
            //         SystemMediaTransportControls object for the current app view.]
            //     3. For each button you want notifications from, set the corresponding property to true to
            //        enable the button.  For example, set IsPlayEnabled to true to enable the "Play" button
            //        and media key.
            //        [Note: the individual button-enabled properties are initialized to false when the
            //         system instantiates the SystemMediaTransportControls object for the current app view.]
            //
            // Here we'll perform 1, and 3 for the buttons that will always be enabled for this scenario (Play,
            // Pause, Stop).  For 2, we purposely set IsEnabled to false to be consistent with the scenario's
            // initial state of no media loaded.  Later in the code where we handle the loading of media
            // selected by the user, we will enable SystemMediaTransportControls.
            systemMediaControls.ButtonPressed += systemMediaControls_ButtonPressed;

            //////// Add event handlers to support requests from the system to change our playback state.
            //////systemMediaControls.PlaybackRateChangeRequested += systemMediaControls_PlaybackRateChangeRequested;
            //////systemMediaControls.AutoRepeatModeChangeRequested += systemMediaControls_AutoRepeatModeChangeRequested;
            //////systemMediaControls.PlaybackPositionChangeRequested += systemMediaControls_PlaybackPositionChangeRequested;

            //////// Subscribe to property changed events to get SoundLevel changes.
            //////systemMediaControls.PropertyChanged += systemMediaControls_PropertyChanged;

            // Note: one of the prerequisites for an app to be allowed to play audio while in background,
            // is to enable handling Play and Pause ButtonPressed events from SystemMediaTransportControls.
            systemMediaControls.IsPlayEnabled  = true;
            systemMediaControls.IsPauseEnabled = true;
            systemMediaControls.IsStopEnabled  = true;
            systemMediaControls.PlaybackStatus = MediaPlaybackStatus.Closed;

            //Nov 2017:
            systemMediaControls.IsRewindEnabled      = true;    // do not show up
            systemMediaControls.IsFastForwardEnabled = true;    // do not show up ==>
            systemMediaControls.IsNextEnabled        = true;    //                ==> using these two instead then.
            systemMediaControls.IsPreviousEnabled    = true;
        }

        async void systemMediaControls_ButtonPressed(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs args)
        {
            // The system media transport control's ButtonPressed event may not fire on the app's UI thread.  XAML controls
            // (including the MediaPlayerElement control in our page as well as the scenario page itself) typically can only be
            // safely accessed and manipulated on the UI thread, so here for simplicity, we dispatch our entire event handling
            // code to execute on the UI thread, as our code here primarily deals with updating the UI and the MediaPlayerElement.
            //
            // Depending on how exactly you are handling the different button presses (which for your app may include buttons
            // not used in this sample scenario), you may instead choose to only dispatch certain parts of your app's
            // event handling code (such as those that interact with XAML) to run on UI thread.
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                // Because the handling code is dispatched asynchronously, it is possible the user may have
                // navigated away from this scenario page to another scenario page by the time we are executing here.
                // Check to ensure the page is still active before proceeding.
                //    if (_isThisPageActive)
                {
                    switch (args.Button)
                    {
                    case SystemMediaTransportControlsButton.Play: mp_Vm.Play(); break;

                    case SystemMediaTransportControlsButton.Pause: mp_Vm.Pause(); break;

                    case SystemMediaTransportControlsButton.Stop: mp_Vm.Pause(); mp_Vm.PlaybackSession.Position = TimeSpan.Zero; break;

                    //case SystemMediaTransportControlsButton.Next: await SetNewMediaItem(currentItemIndex + 1); break;              // range-checking will be performed in SetNewMediaItem()
                    //case SystemMediaTransportControlsButton.Previous: await SetNewMediaItem(currentItemIndex - 1); break;
                    case SystemMediaTransportControlsButton.ChannelDown: await SetNewMediaItem(currentItemIndex - 1); break;

                    case SystemMediaTransportControlsButton.Next: /**/ mp_Vm.PlaybackSession.Position = mp_Vm.PlaybackSession.Position.Add(TimeSpan.FromSeconds(60)); break;
Exemplo n.º 15
0
 public async void ReThumbFile(MediaInfoDto mid)
 {
     await Speak("Not implemented.");
 }
Exemplo n.º 16
0
 public async void DeleteMedia(MediaInfoDto mid)
 {
     await onDeleteDialog(mid);
 }
Exemplo n.º 17
0
 async void genPlayListFromFile_void(MediaInfoDto mid) => await genPlayListFromFile(mid);