Exemple #1
0
        private void ImgMapPlaceIcon_Clicked(object sender, EventArgs e)
        {
            // /*
            switch (currentMedia)
            {
            case CurrentMedia.Image:
                if (postData.HasMapImage())
                {
                    imgMapPlaceIcon.Source = PLACE_IMAGE_ICON_URI;     // Switch the clickable icon back to place
                    currentMedia           = CurrentMedia.Map;
                    if (postData.HasCoordinate())
                    {
                        imgMapViewIcon.IsVisible = true;
                    }
                    imgMedia.Source = postData.GetMapImageSource();
                }
                break;

            case CurrentMedia.Map:
                if (postData.HasPlaceImage())
                {
                    imgMapPlaceIcon.Source   = PLACE_MAP_ICON_URI;   // Switch the clickable icon back to map
                    currentMedia             = CurrentMedia.Image;
                    imgMapViewIcon.IsVisible = false;
                    imgMedia.Source          = postData.GetPlaceImageSource();
                }
                break;
            }
        }
 private void right_Click(object sender, EventArgs e)
 {
     if (CurrentMedia != null)
     {
         CurrentMedia.RotateRight();
         media.Image = CurrentMedia.Small;
     }
 }
Exemple #3
0
        private async Task SetMediaFile(IMediaItem media)
        {
            if (media.VlcMedia != null)
            {
                CurrentMedia = media.VlcMedia;
            }
            else
            {
                var mrl_fromType = media.GetMrlAndFromType();
                LogHelper.Log("SetMRL: " + mrl_fromType.Item2);
                if (Instance == null)
                {
                    await Initialize();
                }
                await PlayerInstanceReady.Task;

                if (!PlayerInstanceReady.Task.Result)
                {
                    LogHelper.Log($"Couldn't play media {media.Name} as VLC failed to init");
                    return;
                }

                CurrentMedia = new Media(Instance, mrl_fromType.Item2, mrl_fromType.Item1);
            }

            // Hardware decoding
            CurrentMedia.addOption(!Locator.SettingsVM.HardwareAccelerationEnabled ? ":avcodec-hw=none" : ":avcodec-hw=d3d11va");
            CurrentMedia.addOption(!Locator.SettingsVM.HardwareAccelerationEnabled ? ":avcodec-threads=0" : ":avcodec-threads=1");
            var pos = await FetchPreviousPosition(media);

            CurrentMedia.addOption($":start-time={pos}");

            if (_mediaPlayer == null)
            {
                _mediaPlayer = new MediaPlayer(CurrentMedia);
                var em = _mediaPlayer.eventManager();

                em.OnBuffering        += Playback_MediaBuffering;
                em.OnStopped          += OnStopped;
                em.OnPlaying          += OnPlaying;
                em.OnPaused           += OnPaused;
                em.OnTimeChanged      += Playback_MediaTimeChanged;
                em.OnEndReached       += OnEndReached;
                em.OnEncounteredError += Playback_MediaFailed;
                em.OnLengthChanged    += Playback_MediaLengthChanged;
                em.OnTrackAdded       += OnTrackAdded;
                em.OnTrackDeleted     += OnTrackDeleted;
                em.OnPlaying          += Playback_MediaPlaying;
                em.OnPaused           += Playback_MediaPaused;
                em.OnOpening          += Playback_Opening;
            }
            else
            {
                _mediaPlayer.setMedia(CurrentMedia);
            }
            _mediaPlayer.outputDeviceSet(AudioClient.audioClient());
            SetEqualizer(Locator.SettingsVM.Equalizer);
        }
Exemple #4
0
 public async void OnButton_Play(object sender, EventArgs args)
 {
     if (CurrentMedia.IsPlaying)
     {
         CurrentMedia.Pause();
     }
     else
     {
         CurrentMedia.Start();
     }
 }
Exemple #5
0
        public void PlayNextSongInPlayList(CancellationToken ct)
        {
            var item   = CurrentPlaylist.Videos[Index++];
            var result = YClient.GetVideoMediaStreamInfosAsync(item.Id).GetAwaiter().GetResult();

            ct.ThrowIfCancellationRequested();
            var url = result.Audio.WithHighestBitrate().Url;

            CurrentMedia.SetDataSource(url);
            CurrentMedia.Prepare();
            CurrentMedia.Start();
            InitializeSongList();
            SongListPage.SetSelectedItem(Index);
        }
Exemple #6
0
        private async Task SetMediaFile(IMediaItem media)
        {
            if (media.VlcMedia != null)
            {
                CurrentMedia = media.VlcMedia;
            }
            else
            {
                var mrl_fromType = media.GetMrlAndFromType();
                LogHelper.Log("SetMRL: " + mrl_fromType.Item2);
                if (Instance == null)
                {
                    await Initialize();
                }
                await PlayerInstanceReady.Task;

                if (!PlayerInstanceReady.Task.Result)
                {
                    LogHelper.Log($"Couldn't play media {media.Name} as VLC failed to init");
                    return;
                }

                CurrentMedia = new Media(Instance, mrl_fromType.Item2, mrl_fromType.Item1);
            }

            // Hardware decoding
            CurrentMedia.addOption(!Locator.SettingsVM.HardwareAccelerationEnabled ? ":avcodec-hw=none" : ":avcodec-hw=d3d11va");
            if (DeviceHelper.GetDeviceType() == DeviceTypeEnum.Phone)
            {
                CurrentMedia.addOption(!Locator.SettingsVM.HardwareAccelerationEnabled ? ":avcodec-threads=0" : ":avcodec-threads=1");
            }

            var pos = FetchPreviousPosition(media);

            CurrentMedia.addOption($":start-time={pos}");


            if (_mediaPlayer == null)
            {
                InitializeMediaPlayer();
            }
            else
            {
                _mediaPlayer.setMedia(CurrentMedia);
            }
            _mediaPlayer.outputDeviceSet(AudioDeviceID);
            SetEqualizer(Locator.SettingsVM.Equalizer);
        }
Exemple #7
0
        public void RunWithCancellation()
        {
            lock (Lock)
            {
                if (Source != null)
                {
                    Source.Cancel();
                }
                Source = new CancellationTokenSource();
            }

            SetArt();
            var token = Source.Token;
            var t     = Task.Run(() =>
            {
                CurrentMedia.Reset();
                token.ThrowIfCancellationRequested();
                PlayNextSongInPlayList(token);
            }, token);
        }
Exemple #8
0
        async void Init()
        {
            currentMedia = CurrentMedia.Image;

            ///////////// Initilize Related Post ////////////
            azkar    = new RelatedPosts(AppResources.AzkarAndSupplicationsTitle, AZKAR_ICON_URI, RelatedPostType.Supplications);
            mistakes = new RelatedPosts(AppResources.MistakesOccurredTitle, MISTAKES_ICON_URI, RelatedPostType.Mistakes);
            ahkam    = new RelatedPosts(AppResources.AhkamAndRulesTitle, AHKAM_ICON_URI, RelatedPostType.Rules);
            virtue   = new RelatedPosts(AppResources.FeaturesAndVirtues, VIRTUE_ICON_URI, RelatedPostType.Virtue);

            List <Post> posts = App.Data.Data;

            posts = posts.Where(x => RelatedPosts.IsRelated(x, postData.PostID)).ToList();
            if (posts != null && posts.Count > 0)
            {
                foreach (Post item in posts)
                {
                    if (item == null || item.Content == null) // ignore the post that does not have a content
                    {
                        continue;
                    }

                    switch (item.Type)
                    {
                    case "place":
                        continue;     // ignore

                    case "azkar":
                        if (this.RelatedPostFilter == PostType.Place || this.RelatedPostFilter == PostType.Azkar)
                        {
                            azkar.Add(item);
                        }
                        break;

                    case "mistake":
                        if (this.RelatedPostFilter == PostType.Place || this.RelatedPostFilter == PostType.Mistake)
                        {
                            mistakes.Add(item);
                        }
                        break;

                    case "ahkam":
                        if (this.RelatedPostFilter == PostType.Place || this.RelatedPostFilter == PostType.Ahkam)
                        {
                            ahkam.Add(item);
                        }
                        break;

                    case "virtue":
                        if (this.RelatedPostFilter == PostType.Place || this.RelatedPostFilter == PostType.Virtue)
                        {
                            virtue.Add(item);
                        }
                        break;
                    }
                }
            }

            InitializeControls();
            imgFavorite.Source = await Helper.GetAutoFavoriteIcon(postData.PostID);

            MainGrid = new Grid()
            {
                Padding           = new Thickness(0, -6, 0, 0),
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                RowSpacing        = 0,
                ColumnSpacing     = 0,
                RowDefinitions    =
                {
                    new RowDefinition {
                        Height = new GridLength(.92, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(.08, GridUnitType.Star)
                    },
                },
            };
            RelatedScrollView = new ScrollView()
            {
                Content = MainStackLayout
            };
            MainGrid.Children.Add(RelatedScrollView);
            MainGrid.Children.Add(gridToolBar, 0, 1);

            this.MainBodyScrollView.Content = null;
            base.MainForAdjDataView.Children.Add(MainGrid);
        }
        protected void PostComment_OnClick(object sender, EventArgs e)
        {
            Comment newComment = CreateFromFields();

            if (this.ReplyToCommentID != 0)
            {
                newComment.ReplyToCommentID = this.ReplyToCommentID;
            }

            var mediaDetail = CurrentMedia.GetLiveMediaDetail();

            if (!mediaDetail.CommentsAreModerated)
            {
                newComment.Status = StatusEnum.Approved.ToString();
            }

            Return ReturnObj = CommentsMapper.Insert(newComment);

            if (ReturnObj != null)
            {
                switch (ReturnObj.IsError)
                {
                case false:
                    if (mediaDetail.CommentsAreModerated)
                    {
                        BasePage.SendMediaCommentApprovalRequest(CurrentMedia, newComment);
                    }

                    if (this.ReplyToCommentID != 0)
                    {
                        var comment = CommentsMapper.GetByID(ReplyToCommentID);

                        if (comment != null)
                        {
                            BasePage.SendMediaReplyToComment(newComment, comment);
                        }
                    }

                    ServerMessage.Visible = true;

                    if (mediaDetail.CommentsAreModerated)
                    {
                        ServerMessage.InnerHtml = "Thank you for your feedback. This is a moderated post. Your comment has been submitted for approval";
                    }
                    else
                    {
                        ServerMessage.InnerHtml = "Thank you for your feedback";
                    }

                    ServerMessage.Attributes["class"] += " alert alert-primary";


                    break;

                case true:
                    ServerMessage.Visible              = true;
                    ServerMessage.InnerHtml            = $"Error adding comment: {ReturnObj.Error}";
                    ServerMessage.Attributes["class"] += " alert alert-danger";

                    Bind();
                    break;
                }
            }
        }
        /* Another way of reading a file by chunks
         *             bool readCompleted = false;
         *     while ( readCompleted == false )
         *     {
         *         int index = 0;
         *         //we're trying to keep reading into our chunk until either we reach the end of the stream, or we've read everything we need.
         *         while (index < chunk.Length)
         *         {
         *             int bytesRead = _bitmapStream.Read(chunk, index, chunk.Length - index);
         *             this.DebugLog("Read the following noof bytes: " + bytesRead);
         *             if (bytesRead == 0)
         *             {
         *                 break;
         *             }
         *             index += bytesRead;
         *         }
         *         if (index != 0) // Our previous chunk may have been the last one
         *         {
         *             string result = Convert.ToBase64String(chunk);
         *             result = result.Trim();
         *             content += result;
         *         }
         *         if (index != chunk.Length) // We didn't read a full chunk: we're done
         *         {
         *             readCompleted = true;
         *             this.DebugLog("No more bytes to read");
         *         }
         *     }
         */



        /* Read the whole file into the byte array. Do not use this method.
         * int length = (int)_bitmapStream.Length;
         * _bitmapStream.Position = 0;
         * byte[] payload = new byte[length];
         * _bitmapStream.Read(payload, 0, length);
         * string result = Convert.ToBase64String(payload);
         * result = result.Trim();
         */

        internal override void OnBeginGetRequestStreamCompleted(IAsyncResult result)
        {
            State state = result.AsyncState as State;

            HttpWebRequest request       = state.Request;
            Stream         contentStream = null;

            if (IsCancelled)
            {
                CompletionMethod(null, null, true, state.Operation);
                return;
            }

            try
            {
                contentStream = request.EndGetRequestStream(result);
            }
            catch (Exception ex)
            {
                CompletionMethod(null, ex, false, state.Operation);
                if (contentStream != null)
                {
                    contentStream.Dispose();
                }
                return;
            }

            Stream _bitmapStream = CurrentMedia.getImageStream();

            if (_bitmapStream == null)
            {
                if (contentStream != null)
                {
                    contentStream.Dispose();
                }

                CompletionMethod(null, new PictureNotAvailableException(), false, state.Operation);
                return;
            }

            try
            {
                //Write the first chunk of data
                string content = "<?xml version=\"1.0\"?><methodCall><methodName>wp.uploadFile</methodName><params>" +
                                 "<param><value><int>" + Blog.BlogId + "</int></value></param>" +
                                 "<param><value><string>" + Credentials.UserName.HtmlEncode() + "</string></value></param>" +
                                 "<param><value><string>" + Credentials.Password.HtmlEncode() + "</string></value></param>" +
                                 "<param><struct><member><name>name</name><value><string>" + CurrentMedia.FileName + "</string></value></member>" +
                                 "<member><name>type</name><value><string>" + CurrentMedia.MimeType.HtmlEncode() + "</string></value></member>" +
                                 "<member><name>bits</name><value><base64>";

                byte[] payload = Encoding.UTF8.GetBytes(content);
                contentStream.Write(payload, 0, payload.Length);

                //Write the chunks of the image
                byte[] chunk = new byte[3600];
                int    count = 0;
                while ((count = _bitmapStream.Read(chunk, 0, chunk.Length)) > 0 && !IsCancelled)
                {
                    payload = Encoding.UTF8.GetBytes(Convert.ToBase64String(chunk).Trim());
                    contentStream.Write(payload, 0, payload.Length);
                }

                if (IsCancelled)
                {
                    return;
                }
                //Write the last chunk of data
                content = "</base64></value></member>" +
                          "<member><name>overwrite</name><value><bool>" + Convert.ToInt32(Overwrite) + "</bool></value></member>" +
                          "</struct></param></params></methodCall>";

                payload = Encoding.UTF8.GetBytes(content);
                contentStream.Write(payload, 0, payload.Length);
            }
            finally
            {
                if (_bitmapStream != null)
                {
                    _bitmapStream.Dispose();
                }
                contentStream.Dispose();
            }

            if (IsCancelled)
            {
                CompletionMethod(null, null, true, state.Operation);
                return;
            }

            lock (_syncRoot)
            {
                if (_isFinished == true)
                {
                    return;                      //Tentative idea on how to fix #209
                }
            }
            state.Operation.Post(onProgressReportDelegate, new ProgressChangedEventArgs(40, state.Operation.UserSuppliedState));

            request.BeginGetResponse(OnBeginFileResponseCompleted, state);
        }