protected override void SetAudioTrack_Call(AudioTrack value)
        {
            int hr = 0;
            if (!value.isExternal)
            {
                isExternalAudio = false;

                IAMStreamSelect stream;
                IBaseFilter filter;
  
                filter = GetFilter(graphBuilder,".mkv");
                stream = (IAMStreamSelect)filter;

                int current = value.Number;
                hr = stream.Enable(current, AMStreamSelectEnableFlags.Enable);
                DsError.ThrowExceptionForHR(hr);

                //Debug.WriteLine("Using subtitles : " +current);
            } 
            else
            {
                isExternalAudio = true;

                if (graphBuilderExtAudio != null) Marshal.ReleaseComObject(graphBuilderExtAudio);
                graphBuilderExtAudio = (IGraphBuilder) new FilterGraph();

                mediaPositionExtAudio   = graphBuilderExtAudio as IMediaPosition;
                mediaControlExtAudio    = graphBuilderExtAudio as IMediaControl;
                basicAudioExtAudio      = graphBuilderExtAudio as IBasicAudio;

                string pathtofile = Path.Combine(FileService.GetPathToLearningItem(value.LearningItem),value.ExternalFile);
                // Have the graph builder construct its the appropriate graph automatically
                try
                {
                    hr = graphBuilderExtAudio.RenderFile(pathtofile, null);
                    DsError.ThrowExceptionForHR(hr);
                }
                catch(Exception ex)
                {
                    SystemMessage.Show(
                        Loc.T("Player.Message.CantOpenExternalAudioFile") +  Environment.NewLine
                        + pathtofile
                        + Environment.NewLine + Environment.NewLine +
                        "Exeption details :" + Environment.NewLine +
                         ex.Message + Environment.NewLine +
                         ex.Source
                        );
                    return;
                }

                #if DEBUG
                    rot = new DsROTEntry(graphBuilderExtAudio);
                #endif

                // Run the graph to play the media file
                hr = mediaControlExtAudio.Run();
                DsError.ThrowExceptionForHR(hr);

                SyncronizeVideoAndAudio();

            }
        }
        public override async void CmdDispatcher(string command)
        {
            string filename;

            switch (command)
            {
                case "AddVideoFile":
                    AddVideoFile_Cmd();
                    break;

                case "AddCover":
                    AddCover_Cmd();
                    break;

                case "Save":
                case "SaveAndClose":
                    //Save();
                    if(command=="SaveAndClose") NavigationService.NavigateBack();
                    break;

                case "Backup":
                    //Save();
                    NavigationService.NavigateForward(Views.Backup,new Backup_parameters() {mode = Backup_parameters.Mode.LearningItem,learningitem = LearningItem});
                    break;

                case "Cancel":
                    //Save();
                    NavigationService.NavigateBack();
                    break;

                case "OpenMainSetting":
                    NavigationService.NavigateForward(Views.AppSettings,new AppSettings_parameters());
                    break;

                case "DownloadYoutubeVideo":
                    DownloadVideoButton.IsEnabled = false;
                    var VideoInfos = YoutubeDownloader.GetVideoInfo(LearningItem.YoutubeURL);
                    if(VideoInfos.Count == 0)
                    {
                        await DialogService.Message(Tx.T("EditLearningItem.Messages.CantGetYoutubeVideoInfo"));
                        DownloadVideoButton.IsEnabled = true;
                        return;
                    }
                    VideoInfo vinf = VideoInfos.OrderByDescending(x => x.Resolution).FirstOrDefault();
                    if(vinf == null)
                    {
                        await DialogService.Message("Cannot found youtube video info");
                        return;
                    }
                    YoutubeDownloader.Info inf = YoutubeDownloader.GetInfo(vinf);
                    LearningItem.VideoFileName = Path.Combine(FileService.GetPathToLearningItem(LearningItem), inf.VideoFileName);

                    await Task.Run(() =>
                    {
                        ProgressBar_Model pb = null;
                        try
                        {
                            pb = new ProgressBar_Model();
                            App.AddLongTaskProgressBar(pb);
                            YoutubeDownloader.Download(VideoInfos, vinf, FileService.GetPathToLearningItem(LearningItem),pb);
                        }
                        catch(Exception ex)
                        {
                            Dispatcher.RequestMainThreadAction(new Action(() => NavigationService.OpenDialog(Views.ExceptionForm, new ExceptionForm_parameters { ex = ex, title = Tx.T("EditLearningItem.Messages.CantGetYoutubeVideo") })));
                        }
                        finally
                        {
                            App.RemoveLongTaskProgressBar(pb);
                        }
                    }
                        
                        
                    );
                    if (inf.isExternalAudio)
                    {
                        if(LearningItem.AudioTracks.Count == 0)
                        {
                            AudioTrack at = new AudioTrack();
                            at.isExternal = true;
                            at.ExternalFile = Path.GetFileName(inf.AudioFileName);
                            LearningItem.AudioTracks.Add(at);
                        }
                    }
                    if (string.IsNullOrEmpty(LearningItem.Name)) LearningItem.Name = vinf.Title;
                    EFDbContext.SaveChgs();
                    if (LearningItem.AudioTrack == null && LearningItem.AudioTracks.Count > 0) LearningItem.AudioTrack = LearningItem.AudioTracks[0];
                    EFDbContext.SaveChgs();
                    DownloadVideoButton.IsEnabled = true;
                    break;
                    /*
                case "EditSubtitles":
                    Player.Pause();
                    NavigationService.NavigateForward(ViewModelLocator.SubtitleEditor,new SubtitleEditor_parameters() { LearningItem = LearningItem });
                    break;
                    */

                case "ExportToFile":
                case "ExportToFileWithoutPrivateData":
                    filename = DialogService.SaveFile("xml (*.xml)|*.xml");
                    if (filename == null) return;
                    //SQL_XML_Operations.SaveLearningItem(filename,LearningItem,!(command=="ExportToFileWithoutPrivateData"));
                    //if (res != SQL_XML_IO_statuses.Ok) await DialogService.Message(Tx.T("EditLearningItem.Messages.UnknownSaveError"));
                    break;

                case "LoadFromFile":
                    filename = DialogService.OpenFile("","xml (*.xml)|*.xml");
                    Guid guid;
                   // SQL_XML_Operations.LoadLearningItem(filename,out guid);
                   /*
                    if (res != SQL_XML_IO_statuses.Ok)
                    {
                        switch (res)
                        {
                            case SQL_XML_IO_statuses.GUIDdoestMatches:
                                await DialogService.Message(Tx.T("EditLearningItem.Messages.GuidDoesntMatches"));
                                break;
                            default:
                                throw new NotImplementedException();
                        }
                    }
                    */
                    break;

                case "AddExternalSubtitles":
                    filename = DialogService.OpenFile("", "srt (*.srt)|*.srt");
                    if (filename == null) return;

                    Subtitles sub = SRTparser.LoadSRTfile(filename);
                    LearningItem.SubtitleCollection.Add(sub);
                    //Save();
                    break;

                case "Publish":
                    NavigationService.OpenDialog(Views.Publish,new Publish_parameters { LearningItem = LearningItem });                   
                    break;

                case "Pause":
                    if (Player.IsPlaying)
                    {
                        Player.Pause();
                    }
                    else
                    {
                        Player.Play();
                    }
                    break;

                default:
                    throw new NotImplementedException();
            }
        }
        EFDbConnect CreateDemoBase(string db_name)
        {
            string path = PathToDb(db_name);
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            ILogger ILoggerMock = Mock.Of<ILogger>();
            ISQLitePlatform platf = new SQLitePlatformWin32();
            EFDbConnect EFDbConnect = new EFDbConnect(platf, path);

            EFDbContext ctx = new EFDbContext(EFDbConnect);

            LearningItem li1 = new LearningItem();
            li1.Name = "First";
            ctx.AddNewItemToDBContext(li1);
            LearningItem li2 = new LearningItem();
            li2.Name = "Second";
            ctx.AddNewItemToDBContext(li2);


            // Audio tracks
            AudioTrack at1 = new AudioTrack();
            li1.AudioTracks.Add(at1);

            AudioTrack at2 = new AudioTrack();
            li1.AudioTracks.Add(at2);

            AudioTrack at3 = new AudioTrack();
            li2.AudioTracks.Add(at3);

            // Frequency dictionary
            FrequencyDictionary fd1 = new FrequencyDictionary();
            FrequencyDictionary fd2 = new FrequencyDictionary();

            FrequencyDictionary.Item fdi1 = new FrequencyDictionary.Item();
            fd1.Items.Add(fdi1);
            FrequencyDictionary.Item fdi2 = new FrequencyDictionary.Item();
            fd1.Items.Add(fdi2);

            FrequencyDictionary.Item fdi3 = new FrequencyDictionary.Item();
            fd2.Items.Add(fdi3);
            FrequencyDictionary.Item fdi4 = new FrequencyDictionary.Item();
            fd2.Items.Add(fdi4);

            // Languages
            Language lang1 = new Language();
            lang1.FrequencyDictionary = fd1;

            Language lang2 = new Language();
            lang2.FrequencyDictionary = fd2;

            Subtitles sub1 = new Subtitles();
            li1.SubtitleCollection.Add(sub1);
            sub1.SecondaryLanguage = lang1;

            Subtitles sub2 = new Subtitles();
            li1.SubtitleCollection.Add(sub2);


            SubtitleItem si1 = new SubtitleItem();
            sub1.Items.Add(si1);
            SubtitleItem si2 = new SubtitleItem();
            sub1.Items.Add(si2);

            SubtitleItem si3 = new SubtitleItem();
            sub2.Items.Add(si3);
            SubtitleItem si4 = new SubtitleItem();
            sub2.Items.Add(si4);

            Subtitles sub3 = new Subtitles();
            li2.SubtitleCollection.Add(sub3);
            sub3.SecondaryLanguage = lang2;

            SubtitleItem si5 = new SubtitleItem();
            sub3.Items.Add(si5);


            WordOfSubtitleItem sw1 = new WordOfSubtitleItem();
            si1.WordsCollection.Add(sw1); 

            WordOfSubtitleItem sw2 = new WordOfSubtitleItem();
            si1.WordsCollection.Add(sw2); 

            WordOfSubtitleItem sw3 = new WordOfSubtitleItem();
            si5.WordsCollection.Add(sw3);



            // Dictionary
            Dictionary dic1 = new Dictionary();
            ctx.AddNewItemToDBContext(dic1);

            WordOfDictionary wd1 = new WordOfDictionary();
            dic1.Words.Add(wd1);

            TranslationOfWord tw1 = new TranslationOfWord();
            wd1.translations.Add(tw1);
            
            TranslationOfWord tw2 = new TranslationOfWord();
            wd1.translations.Add(tw2);

            WordOfDictionary wd2 = new WordOfDictionary();
            dic1.Words.Add(wd2);
            sw1.word_of_dictionary = wd1;
            sw2.word_of_dictionary = wd2;

            Dictionary dic2 = new Dictionary();
            ctx.AddNewItemToDBContext(dic2);
            WordOfDictionary wd3 = new WordOfDictionary();
            dic1.Words.Add(wd3);
            WordOfDictionary wd4 = new WordOfDictionary();
            dic1.Words.Add(wd4);
            sw3.word_of_dictionary = wd3;

            
            
            
            ctx.SaveChanges();

            return EFDbConnect;
        }
Esempio n. 4
0
        private static void AnalizeTrackEntry(EbmlReader ebmlReader, MatroskaElementDescriptorProvider medp, ResultOfParsingMKV resPars, StringBuilder sb, string GroupName = "", string add = "")
        {
            ulong TrackNumber = 0;
            ulong TrackUID = 0;
            ulong TrackType = 0;
            ulong FlagDefault = 0;
            ulong FlagLacing = 0;
            string CodecID = "";
            string Name = "";
            ulong  DefaultDuration = 0;
            string Language = "";
            
            ebmlReader.EnterContainer();
            while (ebmlReader.ReadNext())
            {
                var descriptor = medp.GetElementDescriptor(ebmlReader.ElementId);
                if (descriptor == null)
                {
                    sb.Append(add + "undefined \r\n");
                    continue;
                }
                string dName = descriptor.Name;
                sb.Append(add + dName);

                switch (descriptor.Type)
                {
                    case ElementType.MasterElement:
                        sb.Append("\r\n");
                        //ReadContainer(ebmlReader, medp, dicSub, CurrentClusterTimeCode, sb, descriptor.Name, add + "    ");
                        break;
                    case ElementType.AsciiString:
                        string strVal = ebmlReader.ReadAscii();
                        if(dName == "CodecID") CodecID = strVal; 
                        if (dName == "Language") Language = strVal; 
                        sb.Append(" = " + strVal);
                        break;
                    case ElementType.Binary:
                        break;
                    case ElementType.Date:
                        sb.Append(" = " + ebmlReader.ReadDate());
                        break;
                    case ElementType.Float:
                        double flVal = ebmlReader.ReadFloat();
                        sb.Append(" = " + flVal);
                        break;
                    case ElementType.None:
                        sb.Append(" (none)");
                        break;
                    case ElementType.SignedInteger:
                        sb.Append(" = " + ebmlReader.ReadInt());
                        break;
                    case ElementType.UnsignedInteger:
                        ulong ulVal = ebmlReader.ReadUInt();
                        if(dName == "TrackNumber") TrackNumber = ulVal;
                        if(dName == "TrackType") TrackType = ulVal;
                        if(dName == "FlagDefault") FlagDefault = ulVal;
                        if(dName == "FlagLacing ") FlagLacing = ulVal;
                        if(dName == "DefaultDuration") DefaultDuration = ulVal;
                        if (dName == "TrackUID") TrackUID = ulVal;
                        sb.Append(" = " + ulVal);
                        break;
                    case ElementType.Utf8String:
                        string utfStr = ebmlReader.ReadUtf();
                        if (dName == "Name") Name = utfStr;
                        sb.Append(" = " + utfStr);
                        break;
                }
                sb.Append("\r\n");
            }
            ebmlReader.LeaveContainer();
            
            // If it's subtitles track
            if (TrackType == 17) { 
                Subtitles sub = new Subtitles();
                sub.Items = new SynchronizedObservableCollection<SubtitleItem>();
                sub.Language = Language.Length == 0 ? "eng" : Language;
                sub.Type = Name;
                sub.Format = CodecID;
                sub.TrackUID = (long)TrackUID;

                resPars.dicSub.Add(Convert.ToInt16(TrackNumber),sub);
            }

            // If it's subtitles track
            if (TrackType == 2)
            {
                AudioTrack aud = new AudioTrack();
                aud.Language = Language.Length == 0 ? "eng" : Language;
                aud.CodecID = CodecID;
                aud.Number = resPars.AudioTracks.Count + 1;

                resPars.AudioTracks.Add(aud);
            }

        }
Esempio n. 5
0
 abstract protected void SetAudioTrack_Call(AudioTrack value);
Esempio n. 6
0
 public void SetAudioTrack(AudioTrack track)
 {
     #if (DEBUG_PLAYER)
         Logger.Write<Player>(LogMsgType.DeepTrace,"Player: set audio track");
     #endif
     if (track == null) return;
     try
     {
         SetAudioTrack_Call(track);
     } catch
     {
         AddDelayedSetOperations(new DelayedOperation { type = enDelayedOperations.SetAudioTrack, value = track });
     }
 }
Esempio n. 7
0
        protected override void SetAudioTrack_Call(AudioTrack value)
        {
            if (!value.isExternal)
            {
                isExternalAudio = false;
            } 
            else
            {
                isExternalAudio = true;

                if (MediaElementAudio == null)
                {
                    MediaElement.Dispatcher.Invoke(() =>
                    {
                        MediaElementAudio = new MediaElement();
                        host.Children.Add(MediaElementAudio);
                        MediaElementAudio.LoadedBehavior = MediaState.Manual;
                        MediaElementAudio.UnloadedBehavior = MediaState.Stop;

                    });
                }

                string pathtofile = Path.Combine(FileService.GetPathToLearningItem(value.LearningItem),value.ExternalFile);

                MediaElementAudio.Dispatcher.Invoke(()=> {
                    MediaElementAudio.Source = new Uri(pathtofile);
                    if(isPlaying) MediaElementAudio.Play();
                    MediaElementAudio.Volume = MediaElement.Volume;
                });
                
                SyncronizeVideoAndAudio();
            }
        }