Exemple #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Page> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null)
            {
                return;
            }


            var layout = new Android.Widget.LinearLayout(this.Context);

            layout.SetBackgroundColor(Android.Graphics.Color.Black);
            layout.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
            VideoView mVideoView = new VideoView(Context);

            mVideoView.SetVideoPath("android.resource://" + this.Context.PackageName + "/" + Resource.Drawable.IntroGladys);
            layout.SetVerticalGravity(GravityFlags.Center);
            layout.SetHorizontalGravity(GravityFlags.Center);
            mVideoView.LayoutParameters = new LayoutParams(LayoutParams.FillParent, LayoutParams.FillParent);
            layout.AddView(mVideoView);
            mVideoView.Start();
            _view = layout;
            AddView(_view);
        }
Exemple #2
0
        private void InitComponent()
        {
            try
            {
                var media = new MediaController(this);
                media.Show(5000);

                ProgressBar            = FindViewById <ProgressBar>(Resource.Id.progress_bar);
                ProgressBar.Visibility = ViewStates.Visible;

                PostVideoView             = FindViewById <VideoView>(Resource.Id.videoView);
                PostVideoView.Completion += PostVideoViewOnCompletion;
                PostVideoView.SetMediaController(media);
                PostVideoView.Prepared += PostVideoViewOnPrepared;
                PostVideoView.CanSeekBackward();
                PostVideoView.CanSeekForward();
                PostVideoView.SetAudioAttributes(new AudioAttributes.Builder().SetUsage(AudioUsageKind.Media).SetContentType(AudioContentType.Movie).Build());

                if (VideoUrl.Contains("http"))
                {
                    PostVideoView.SetVideoURI(Uri.Parse(VideoUrl));
                }
                else
                {
                    var file = Uri.FromFile(new File(VideoUrl));
                    PostVideoView.SetVideoPath(file.Path);
                }

                TabbedMainActivity.GetInstance()?.SetOnWakeLock();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
 private void SetSource()
 {
     try
     {
         if (string.IsNullOrWhiteSpace(Element.Source))
         {
             return;
         }
         _prepared = false;
         if (Element.Source.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase) ||
             Element.Source.StartsWith("https://", StringComparison.CurrentCultureIgnoreCase))
         {
             _videoView.SetVideoURI(Android.Net.Uri.Parse(Element.Source));
         }
         else
         {
             _videoView.SetVideoPath(Element.Source);
         }
         _videoView.RequestFocus();
         //  _videoView.SetOnPreparedListener(new VideoLoop());
         //_videoView.SetOnPreparedListener(new OnPreparedListener());
     }
     catch (Java.Lang.Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         Element.OnError(e.Message);
     }
 }
        void SetSource()
        {
            isPrepared = false;
            bool hasSetSource = false;

            if (Element.Source is UriVideoSource)
            {
                string uri = (Element.Source as UriVideoSource).Uri;

                if (!String.IsNullOrWhiteSpace(uri))
                {
                    videoView.SetVideoURI(Android.Net.Uri.Parse(uri));
                    hasSetSource = true;
                }
            }
            else if (Element.Source is FileVideoSource)
            {
                string filename = (Element.Source as FileVideoSource).File;

                if (!String.IsNullOrWhiteSpace(filename))
                {
                    videoView.SetVideoPath(filename);
                    hasSetSource = true;
                }
            }

            if (hasSetSource && Element.AutoPlay)
            {
                videoView.Start();
            }
        }
Exemple #5
0
        private void ResetVideo()
        {
            var source = Element.Source;

            if (source == null)
            {
                videoView.SetVideoURI(null);
                return;
            }

            var filePath = source.FilePath;

            if (filePath != null)
            {
                videoView.SetVideoPath(filePath);
                videoView.SeekTo(1);
                return;
            }

            var fileUri = source.Url;

            if (fileUri != null)
            {
                videoView.SetVideoURI(Android.Net.Uri.Parse(fileUri));
                videoView.SeekTo(1);
                return;
            }
        }
        void SetSource()
        {
            isPrepared          = false;
            hasSetSource        = false;
            videoView.Activated = true;
            videoView.StopPlayback();

            if (Element.Source is UriVideoSource source)
            {
                string uri = source.Uri;

                if (!string.IsNullOrWhiteSpace(uri))
                {
                    videoView.SetVideoURI(Android.Net.Uri.Parse(uri));
                    hasSetSource = true;
                }
            }
            else if (Element.Source is FileVideoSource videoSource)
            {
                string filename = videoSource.File;

                if (!string.IsNullOrWhiteSpace(filename))
                {
                    videoView.SetVideoPath(filename);
                    hasSetSource = true;
                }
            }
        }
        private void Init()
        {
            try
            {
                #region initialize
                statusTitle = Intent.GetStringExtra("title");
                videoPath   = Intent.GetStringExtra("videoUrl");
                ID          = Intent.GetIntExtra("videoId", -1);

                TextView     videoTitle                 = FindViewById <TextView>(Resource.Id.toolbar_title);
                VideoView    videoView                  = FindViewById <VideoView>(Resource.Id.full_screen_video);
                LinearLayout btnShareVideo              = FindViewById <LinearLayout>(Resource.Id.btn_share);
                LinearLayout btnShareVideoWithWhatsapp  = FindViewById <LinearLayout>(Resource.Id.btn_share_whatsapp);
                LinearLayout btnShareVideoWithInstagram = FindViewById <LinearLayout>(Resource.Id.btn_share_instagram);
                LinearLayout btnShareVideoWithFacebook  = FindViewById <LinearLayout>(Resource.Id.btn_share_facebook);
                LinearLayout btnDownloadVideo           = FindViewById <LinearLayout>(Resource.Id.btn_download);
                LinearLayout btnLikeVideo               = FindViewById <LinearLayout>(Resource.Id.btn_like);
                progress = FindViewById <ProgressBar>(Resource.Id.loading);
                imgLike  = FindViewById <ImageView>(Resource.Id.img_like);
                imgCover = FindViewById <ImageView>(Resource.Id.img_cover);

                videoTitle.Text = statusTitle;
                Glide.With(this).Load(Intent.GetStringExtra("coverUrl")).Into(imgCover);

                if (Preferences.ContainsKey("favorites", ID.ToString()))
                {
                    imgLike.SetImageResource(Resource.Drawable.heart);
                }

                videoView.SetVideoPath(Intent.GetStringExtra("videoUrl"));
                videoView.SetMediaController(new MediaController(this));
                videoView.SetOnPreparedListener(this);
                videoView.SetOnCompletionListener(this);
                videoView.SetOnErrorListener(this);

                LoadAds();

                int catId = Intent.GetIntExtra("catId", -1);
                SupportFragmentManager.BeginTransaction().Replace(Resource.Id.frameLayout, new VideosFragment(catId != -1 ? catId : 3)).Commit();
                #endregion

                #region Buttons Click Events
                btnShareVideoWithWhatsapp.Click  += BtnShareOnWhatsapp_Click;
                btnShareVideoWithInstagram.Click += BtnShareOnInstagram_Click;
                btnShareVideoWithFacebook.Click  += BtnShareOnFacebook_Click;
                btnShareVideo.Click    += BtnShareVideo_Click;
                btnDownloadVideo.Click += BtnDownloadVideo_Click;
                btnLikeVideo.Click     += BtnLikeVideo_Click;
                #endregion
            }
            catch
            {
                Toast.MakeText(this, GetString(Resource.String.error), ToastLength.Short).Show();
            }
        }
        private void SetVideoStory(string url)
        {
            try
            {
                StoryImageView.Visibility = StoryImageView.Visibility switch
                {
                    ViewStates.Visible => ViewStates.Gone,
                    _ => StoryImageView.Visibility
                };

                StoryVideoView.Visibility = StoryVideoView.Visibility switch
                {
                    ViewStates.Gone => ViewStates.Visible,
                    _ => StoryVideoView.Visibility
                };

                PlayIconVideo.Visibility = ViewStates.Visible;
                PlayIconVideo.Tag        = "Play";
                PlayIconVideo.SetImageResource(Resource.Drawable.ic_play_arrow);

                switch (StoryVideoView.IsPlaying)
                {
                case true:
                    StoryVideoView.Suspend();
                    break;
                }

                if (url.Contains("http"))
                {
                    StoryVideoView.SetVideoURI(Uri.Parse(url));
                }
                else
                {
                    var file = Uri.FromFile(new File(url));
                    StoryVideoView.SetVideoPath(file?.Path);
                }
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
Exemple #9
0
 protected override void OnCreate(Bundle bundle)
 {
     base.OnCreate(bundle);
     // Set our view from the "main" layout resource
     SetContentView(Resource.Layout.VideoActivity);
     videoView = FindViewById <VideoView> (Resource.Id.SampleVideoView);
     videoView.SetMediaController(new MediaController(this));
     videoView.SetVideoPath($"android.resource://{PackageName}/{Resource.Raw.bunny}");
     videoView.RequestFocus();
     videoView.Start();
 }
Exemple #10
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById <Button>(Resource.Id.MyButton);

            VideoView videoView = FindViewById <VideoView>(Resource.Id.videoView1);

            button.Click += delegate
            {
                videoView.StopPlayback();

                string url = "http://192.168.0.10:12300/NNDDServer/sm29577290";

                System.Net.WebRequest req = System.Net.WebRequest.Create(url);

                System.Net.WebResponse res = req.GetResponse();

                using (Stream stream = res.GetResponseStream())
                {
                    Java.IO.File[] files = GetExternalCacheDirs();
                    Java.IO.File   dir   = files[0];

                    string tempFilePath = dir.AbsolutePath + "/temp_video.mp4";

                    if (File.Exists(tempFilePath))
                    {
                        File.Delete(tempFilePath);
                    }

                    FileStream tempFile = File.Create(tempFilePath);

                    stream.CopyTo(tempFile);
                    stream.Close();
                    tempFile.Close();

                    videoView.SetVideoPath(tempFilePath);

                    //videoView.SetVideoURI(uri);
                    //videoView.Start();
                }
            };

            videoView.Prepared += delegate
            {
                videoView.Start();
            };
        }
        private void SetVideoStory(string url)
        {
            try
            {
                TxtEdit.Visibility = ViewStates.Gone;

                if (StoryImageView.Visibility == ViewStates.Visible)
                {
                    StoryImageView.Visibility = ViewStates.Gone;
                }

                if (StoryVideoView.Visibility == ViewStates.Gone)
                {
                    StoryVideoView.Visibility = ViewStates.Visible;
                }

                PlayIconVideo.Visibility = ViewStates.Visible;
                PlayIconVideo.Tag        = "Play";
                PlayIconVideo.SetImageResource(Resource.Drawable.ic_play_arrow);

                if (StoryVideoView.IsPlaying)
                {
                    StoryVideoView.Suspend();
                }

                if (url.Contains("http"))
                {
                    StoryVideoView.SetVideoURI(Android.Net.Uri.Parse(url));
                }
                else
                {
                    var file = Android.Net.Uri.FromFile(new File(url));
                    StoryVideoView.SetVideoPath(file.Path);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemple #12
0
        void UpdateSource(bool forceSeek = false)
        {
            bool hasSetSource = false;

            if (Element.Source is UriVideoSource)
            {
                string uri = (Element.Source as UriVideoSource).Uri;

                if (!String.IsNullOrWhiteSpace(uri))
                {
                    Android.Net.Uri parsedUri = Android.Net.Uri.Parse(uri);
                    videoView.SetVideoURI(parsedUri);
                    hasSetSource = true;
                }
            }
            else if (Element.Source is FileVideoSource)
            {
                string filename = (Element.Source as FileVideoSource).File;

                if (!String.IsNullOrWhiteSpace(filename))
                {
                    videoView.SetVideoPath(filename);
                    hasSetSource = true;
                }
            }
            else if (Element.Source is ResourceVideoSource)
            {
                string package = Context.PackageName;
                string path    = (Element.Source as ResourceVideoSource).Path;

                if (!String.IsNullOrWhiteSpace(path))
                {
                    string filename = Path.GetFileNameWithoutExtension(path).ToLowerInvariant();
                    string uri      = "android.resource://" + package + "/raw/" + filename;
                    videoView.SetVideoURI(Android.Net.Uri.Parse(uri));
                    hasSetSource = true;
                }
            }

            if (hasSetSource)
            {
                if (Element.StartTime > 0)
                {
                    videoView.SeekTo(Element.StartTime * 1000);
                }
                else if (forceSeek)
                {
                    videoView.SeekTo(1); // SeekTo(0) does not do anything, so using 1
                }
            }
        }
        void SetSource()
        {
            _logger.Log("SetSource invoked.");

            isPrepared = false;
            bool hasSetSource = false;

            if (Element.Source is UriVideoSource)
            {
                string uri = (Element.Source as UriVideoSource).Uri;

                if (!String.IsNullOrWhiteSpace(uri))
                {
                    videoView.SetVideoURI(Android.Net.Uri.Parse(uri));
                    hasSetSource = true;
                }
            }
            else if (Element.Source is FileVideoSource)
            {
                string filename = (Element.Source as FileVideoSource).File;

                if (!String.IsNullOrWhiteSpace(filename))
                {
                    videoView.SetVideoPath(filename);
                    hasSetSource = true;
                }
            }
            else if (Element.Source is ResourceVideoSource)
            {
                string package = Context.PackageName;
                string path    = (Element.Source as ResourceVideoSource).Path;

                if (!String.IsNullOrWhiteSpace(path))
                {
                    string filename = Path.GetFileNameWithoutExtension(path).ToLowerInvariant();
                    string uri      = "android.resource://" + package + "/raw/" + filename;
                    videoView.SetVideoURI(Android.Net.Uri.Parse(uri));
                    hasSetSource = true;
                }
            }

            if (hasSetSource && Element.AutoPlay)
            {
                videoView.Start();
            }
        }
        private void SetSource()
        {
            _isPrepared = false;
            var hasSetSource = false;

            if (Element.Source is UriVideoSource)
            {
                var uri = (Element.Source as UriVideoSource).Uri;

                if (!string.IsNullOrWhiteSpace(uri))
                {
                    _videoView.SetVideoURI(Uri.Parse(uri));
                    hasSetSource = true;
                }
            }
            else if (Element.Source is FileVideoSource)
            {
                var filename = (Element.Source as FileVideoSource).File;

                if (!string.IsNullOrWhiteSpace(filename))
                {
                    _videoView.SetVideoPath(filename);
                    hasSetSource = true;
                }
            }
            else if (Element.Source is ResourceVideoSource)
            {
                var package = Context.PackageName;
                var path    = (Element.Source as ResourceVideoSource).Path;

                if (!string.IsNullOrWhiteSpace(path))
                {
                    var filename = Path.GetFileNameWithoutExtension(path).ToLowerInvariant();
                    var uri      = "android.resource://" + package + "/raw/" + filename;
                    _videoView.SetVideoURI(Uri.Parse(uri));
                    hasSetSource = true;
                }
            }

            if (hasSetSource && Element.AutoPlay)
            {
                _videoView.Start();
            }
        }
Exemple #15
0
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);
                SetResult(Result.Ok);
                RequestWindowFeature(WindowFeatures.NoTitle);
                Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);

                var layout = new LinearLayout(this);

                layout.SetBackgroundColor(Color.Black);
                layout.SetGravity(GravityFlags.Center);

                var view = new VideoView(this);

                if (Intent.Extras == null)
                {
                    Finish();
                    return;
                }
                var videoUri = Intent.Extras.GetString("source");

                if (videoUri == null)
                {
                    Finish();
                    return;
                }

                view.SetVideoPath(videoUri);
                view.Completion += (o, e) => Finish();

                if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
                {
                    view.SystemUiVisibility = StatusBarVisibility.Hidden;
                }

                var controller = new FullscreenMediaController(this, view);

                view.SetMediaController(controller);

                layout.AddView(view);
                SetContentView(layout);

                view.Start();
            }
Exemple #16
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_video);

            String videoPath = Intent.GetStringExtra(VIDEO_PATH);

            VideoView = FindViewById <VideoView>(Resource.Id.videoview_video);

            MediaController mediaController = new MediaController(this);

            mediaController.SetAnchorView(VideoView);

            VideoView.SetMediaController(mediaController);
            VideoView.SetVideoPath(videoPath);
            VideoView.SetOnPreparedListener(new MediaPlayerListener());
            VideoView.SetOnCompletionListener(new MediaPlayerListener());
        }
Exemple #17
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName == VideoPlayer.SourceProperty.PropertyName)
            {
                if (!string.IsNullOrEmpty(Element.Source))
                {
                    videoView.SetVideoPath(Element.Source);
                }
            }

            else if (e.PropertyName == VideoPlayer.PositionProperty.PropertyName)
            {
                if (Math.Abs(videoView.CurrentPosition - Element.Position.TotalMilliseconds) > 1000)
                {
                    videoView.SeekTo((int)Element.Position.TotalMilliseconds);
                }
            }
        }
Exemple #18
0
        public void SetvideoStory(string url)
        {
            try
            {
                if (imagstoryDisplay.Visibility == ViewStates.Visible)
                {
                    imagstoryDisplay.Visibility = ViewStates.Gone;
                }

                if (videoView.Visibility == ViewStates.Gone)
                {
                    videoView.Visibility = ViewStates.Visible;
                }

                Btn_Video_icon.Visibility = ViewStates.Visible;

                Btn_Video_icon.Tag = "Play";
                Btn_Video_icon.SetImageResource(Resource.Drawable.ic_play_arrow);

                LoadingProgressBarview.Visibility = ViewStates.Visible;

                if (videoView.IsPlaying)
                {
                    videoView.Suspend();
                }

                if (url.Contains("http"))
                {
                    videoView.SetVideoURI(Android.Net.Uri.Parse(url));
                }
                else
                {
                    var file = Android.Net.Uri.FromFile(new File(url));
                    videoView.SetVideoPath(file.Path);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        private void InitComponent()
        {
            try
            {
                MediaC = new MediaController(this);
                MediaC.Show(5000);

                ProgressBar            = FindViewById <ProgressBar>(Resource.Id.progress_bar);
                ProgressBar.Visibility = ViewStates.Visible;

                PostVideoView = FindViewById <VideoView>(Resource.Id.videoView);

                MediaC.SetAnchorView(PostVideoView);

                PostVideoView.Completion += PostVideoViewOnCompletion;
                PostVideoView.SetMediaController(MediaC);
                PostVideoView.Prepared += PostVideoViewOnPrepared;
                PostVideoView.CanSeekBackward();
                PostVideoView.CanSeekForward();
                //PostVideoView.KeepScreenOn = true;
                //PostVideoView.BringToFront();
                //PostVideoView.Activated = true;

                PostVideoView.SetAudioAttributes(new AudioAttributes.Builder().SetUsage(AudioUsageKind.Media).SetContentType(AudioContentType.Movie).Build());

                if (VideoUrl.Contains("http"))
                {
                    PostVideoView.SetVideoURI(Uri.Parse(VideoUrl));
                }
                else
                {
                    var file = Uri.FromFile(new File(VideoUrl));
                    PostVideoView.SetVideoPath(file.Path);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemple #20
0
        //Overridhen onCreate method
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Log.Debug(TAG, "VideoSplashActivity.OnCreate");

            //setting the Layout view
            SetContentView(Resource.Layout.SplashLayout);

            //accessing the video view id that is specified in Splash Layout video view
            videoView = FindViewById <VideoView>(Resource.Id.splashVideo);

            //accessing the path of the video
            string path = string.Format("android.resource://{0}/{1}", Application.PackageName, Resource.Raw.earth);

            videoView.SetVideoPath(path);
            videoView.Start();

            videoView.Completion += (o, e) =>
            {
                SimulateStartup();
            };
        }
Exemple #21
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);


            // VideoViewのオブジェクトを取得して再生を開始
            videoView = FindViewById <VideoView>(Resource.Id.videoview);

            // >> video のファイルを Resource > Drawableフォルダに入れて,fileをファイル名に書き換える<<
            videoView.SetVideoPath($"android.resource://" + PackageName + "/" + Resource.Drawable.file);

            //MediaController mediaController = new MediaController(this);
            //mediaController.SetAnchorView(videoView);

            //videoView.Visibility = ViewStates.Visible;
            //videoView.SetMediaController(mediaController);

            videoView.Touch += VideoView_Touch;
            videoView.Start();

            textview = FindViewById <TextView>(Resource.Id.txtMsg);

            new System.Threading.Thread(
                new System.Threading.ThreadStart(delegate()
            {
                while (true)
                {
                    System.Threading.Thread.Sleep(100);
                    RunOnUiThread(() => textview.Text = videoView.CurrentPosition.ToString());

                    // ここでビデオの再生時間に応じた処理
                }
            })
                ).Start();
        }
 public void SetSource(string uri)
 {
     _videoView.SetVideoPath(uri);
     State = PlayerState.Preparing;
 }
        private async Task SetStory(FetchStoriesObject.Story story)
        {
            try
            {
                StoryId = story.Id.ToString();
                LastSeenTextView.Text = Methods.Time.ReplaceTime(story.TimeText);

                if (string.IsNullOrEmpty(story.Caption) || string.IsNullOrWhiteSpace(story.Caption))
                {
                    StoryaboutLayout.Visibility = ViewStates.Gone;
                }
                else
                {
                    StoryaboutLayout.Visibility = ViewStates.Visible;
                    CaptionStoryTextView.Text   = Methods.FunString.DecodeString(story.Caption);
                }
                MediaFile = story.MediaFile;

                if (StoryVideoView == null)
                {
                    InitVideoView();
                }

                var type = Methods.AttachmentFiles.Check_FileExtension(MediaFile);
                if (type == "Video")
                {
                    //Show a progress
                    //RunOnUiThread(() => { try { AndHUD.Shared.Show(this, GetText(Resource.String.Lbl_Loading)); }catch (Exception e) { Console.WriteLine(e); } });

                    var fileName = MediaFile.Split('/').Last();
                    MediaFile = AppTools.GetFile(DateTime.Now.Day.ToString(), Methods.Path.FolderDiskStory, fileName, MediaFile);

                    StoryImageView.Visibility = ViewStates.Gone;
                    StoryVideoView.Visibility = ViewStates.Visible;
                    if (MediaFile.Contains("http"))
                    {
                        StoryVideoView.SetVideoURI(Uri.Parse(MediaFile));
                        StoryVideoView.Start();
                    }
                    else
                    {
                        var file = Uri.FromFile(new File(MediaFile));
                        StoryVideoView.SetVideoPath(file.Path);
                        StoryVideoView.Start();
                    }

                    await Task.Delay(500);
                }
                else
                {
                    StoryImageView.Visibility = ViewStates.Visible;
                    StoryVideoView.Visibility = ViewStates.Gone;

                    Glide.With(this).Load(story.MediaFile).Apply(new RequestOptions()).Into(StoryImageView);

                    // GlideImageLoader.LoadImage(this,story.MediaFile, StoryImageView, ImageStyle.CenterCrop, ImagePlaceholders.Drawable);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        void SetSource()
        {
            isPrepared = false;
            bool hasSetSource = false;

            if (Element.Source is UriVideoSource)
            {
                string uri = (Element.Source as UriVideoSource).Uri;

                if (uri.Contains("Bearer="))
                {
                    string[] stringSeparators = new string[] { "Bearer=" };
                    string[] split;


                    split = uri.Split(stringSeparators, StringSplitOptions.None);


                    if (split != null && split.Length == 2)
                    {
                        string bearer = "Bearer " + split[1];
                        if (!String.IsNullOrWhiteSpace(split[0]))
                        {
                            Dictionary <string, string> RequestHeaders = new Dictionary <string, string>();
                            RequestHeaders.Add("Authorization", bearer);

                            videoView.SetVideoURI(NSUri.Parse(split[0]), RequestHeaders);
                            hasSetSource = true;
                        }
                    }
                }
                else if (!String.IsNullOrWhiteSpace(uri))
                {
                    videoView.SetVideoURI(NSUri.Parse(uri));
                    hasSetSource = true;
                }
            }
            else if (Element.Source is FileVideoSource)
            {
                string filename = (Element.Source as FileVideoSource).File;

                if (!String.IsNullOrWhiteSpace(filename))
                {
                    videoView.SetVideoPath(filename);
                    hasSetSource = true;
                }
            }
            else if (Element.Source is ResourceVideoSource)
            {
                string package = Context.PackageName;
                string path    = (Element.Source as ResourceVideoSource).Path;

                if (!String.IsNullOrWhiteSpace(path))
                {
                    string filename = System.IO.Path.GetFileNameWithoutExtension(path).ToLowerInvariant();
                    string uri      = "android.resource://" + package + "/raw/" + filename;
                    videoView.SetVideoURI(NSUri.Parse(uri));
                    hasSetSource = true;
                }
            }

            if (hasSetSource && Element.AutoPlay)
            {
                videoView.Start();
            }
        }
Exemple #25
0
        protected override void OnCreate
        (
            Bundle bundle
        )
        {
            base.OnCreate(bundle);

            _audioPath = Intent.GetStringExtra(AudioPathExtra);

            if (_audioPath == null)
            {
                throw new InvalidOperationException(string.Format("'{0}' extra string missing.",
                                                                  AudioPathExtra));
            }

            _orientationListener = new AndroidCameraActivity.DeviceOrientationEventListener
                                   (
                this,
                SensorDelay.Normal,
                OrientationChanged
                                   );

            _orientationListener.Enable();

            SetContentView(Resource.Layout.PlayVideoLayout);

            _videoView = FindViewById <VideoView>(Resource.Id.PlayedVideo);

            _mediaController = new MediaController(this,
                                                   useFastForward: false);

            _mediaController.SetAnchorView(_videoView);
            _videoView.SetMediaController(_mediaController);

            _videoView.SetOnPreparedListener
            (
                new VideoPreparedListener
                (
                    () =>
            {
                _videoView.SeekTo(1);
                _mediaController.Show();
            }
                )
            );

            _videoView.SetOnCompletionListener
            (
                new VideoCompletionListener
                (
                    () => _mediaController.Show()
                )
            );

            _videoView.SetOnErrorListener
            (
                new VideoErrorListener
                (
                    this,
                    _audioPath,
                    getString: (resource) => { return(GetString(resource)); }
                )
            );

            //_imageView.Touch -= TouchImage;
            //_imageView.Touch += TouchImage;

            /*_videoView.Post // wait with image loading until view fully initialised
             * (
             * () => PlayVideoAsync()
             * );*/

            _videoView.SetVideoPath(_audioPath);
        }
Exemple #26
0
        //ProgressDialog progressDialog;
        protected override void OnElementChanged(ElementChangedEventArgs <VideoViewCustom> e)
        {
            base.OnElementChanged(e);
            try
            {
                base.OnElementChanged(e);
                var activity = Context as Activity;
                activity.RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
                var crossVideoPlayerView = Element as VideoViewCustom;

                if ((crossVideoPlayerView != null) && (e.OldElement == null))
                {
                    var metrics         = Resources.DisplayMetrics;
                    var videoView       = new VideoView(activity);
                    var mediaController = new MediaController(activity);
                    mediaController.SetAnchorView(videoView);
                    videoView.SetMediaController(mediaController);
                    videoView.SetVideoPath(e.NewElement.VideoSource);

                    videoView.Touch += (sender, videoEvent) =>
                    {
                        if (!(videoEvent.Event.Action == Android.Views.MotionEventActions.Down))
                        {
                            return;
                        }
                        if (!mediaController.IsShown)
                        {
                            mediaController.Show();
                            crossVideoPlayerView.GetEventShowView();
                        }
                        else
                        {
                            mediaController.Hide();
                            crossVideoPlayerView.GetEventHidView();
                        }
                    };

                    //progressDialog = new ProgressDialog(Context);
                    //progressDialog.Indeterminate = true;
                    //progressDialog.SetProgressStyle(ProgressDialogStyle.Spinner);
                    //progressDialog.SetMessage("Contacting server. Please wait...");
                    //progressDialog.SetCancelable(false);
                    //progressDialog.Show();

                    videoView.Prepared += (obj, args) =>
                    {
                        var MyMediaPlayer = obj as MediaPlayer;
                        MyMediaPlayer.Prepared += (Prepared_obj, Prepared_args) =>
                        {
                            //Insert Prepared Code Here
                            var tx = "ok";
                        };
                        MyMediaPlayer.Completion += (Completion_obj, Completion_args) =>
                        {
                            //Insert Completion Code Here
                        };
                        MyMediaPlayer.Error += (Error_obj, Error_args) =>
                        {
                            //Insert Error Code Here
                            // progressDialog.Show();
                        };

                        bool IsFirstShow = true;

                        MyMediaPlayer.BufferingUpdate += (bfObj, bfPro) =>
                        {
                            if (IsFirstShow)
                            {
                                //progressDialog.Dismiss();
                                IsFirstShow = false;
                            }
                            else if (!MyMediaPlayer.IsPlaying)
                            {
                            }
                            //else if (!IsConnected)
                            //{
                            //    progressDialog.Show();
                            //    IsFirstShow = false;
                            //}
                            //else if (!CheckInternetConnection())
                            //{
                            //    progressDialog.Show();
                            //    IsFirstShow = false;
                            //}
                            else
                            {
                                IsFirstShow = true;
                            }
                        };


                        long duration = MyMediaPlayer.Duration / 1000;
                        long hours    = duration / 3600;
                        long minutes  = (duration - hours * 3600) / 60;
                        long seconds  = duration - (hours * 3600 + minutes * 60);
                    };

                    crossVideoPlayerView.SetLeaveView += () =>
                    {
                        activity.RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
                        activity.RequestedOrientation = Android.Content.PM.ScreenOrientation.Locked;
                    };
                    crossVideoPlayerView.SetFullScreen += (IsFullScreen) =>
                    {
                        if (IsFullScreen)
                        {
                            activity.RequestedOrientation = Android.Content.PM.ScreenOrientation.Landscape;
                            activity.RequestedOrientation = Android.Content.PM.ScreenOrientation.Locked;
                        }
                        else
                        {
                            activity.RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
                            activity.RequestedOrientation = Android.Content.PM.ScreenOrientation.Locked;
                        }
                    };

                    videoView.Start();
                    SetNativeControl(videoView);
                }
            }
            catch (System.Exception)
            {
            }
        }
Exemple #27
0
 void play(string fullPath)
 {
     videoView.SetVideoPath(fullPath);
     videoView.BringToFront();
     videoView.Start();
 }
        private async Task SetStory(GetUserStoriesObject.StoryObject.Story story)
        {
            try
            {
                StoryId = story.Id;
                LastSeenTextView.Text = Methods.Time.TimeAgo(Convert.ToInt32(story.Posted));

                //image and video
                MediaFile = !story.Thumbnail.Contains("avatar") && story.Videos.Count == 0
                    ? story.Thumbnail
                    : story.Videos[0].Filename;

                if (StoryVideoView == null)
                {
                    InitVideoView();
                }

                string caption = "";
                if (!string.IsNullOrEmpty(story.Description))
                {
                    caption = story.Description;
                }
                else if (!string.IsNullOrEmpty(story.Title))
                {
                    caption = story.Title;
                }

                if (string.IsNullOrEmpty(caption) || string.IsNullOrWhiteSpace(caption))
                {
                    StoryaboutLayout.Visibility = ViewStates.Gone;
                }
                else
                {
                    StoryaboutLayout.Visibility = ViewStates.Visible;
                    CaptionStoryTextView.Text   = Methods.FunString.DecodeString(caption);
                }

                if (StoryVideoView == null)
                {
                    InitVideoView();
                }

                var type = Methods.AttachmentFiles.Check_FileExtension(MediaFile);
                if (type == "Video")
                {
                    //Show a progress
                    //RunOnUiThread(() => { try { AndHUD.Shared.Show(this, GetText(Resource.String.Lbl_Loading)); }catch (Exception e) { Console.WriteLine(e); } });

                    var fileName = MediaFile.Split('/').Last();
                    MediaFile = WoWonderTools.GetFile(DateTime.Now.Day.ToString(), Methods.Path.FolderDiskStory, fileName, MediaFile);

                    StoryImageView.Visibility = ViewStates.Gone;
                    StoryVideoView.Visibility = ViewStates.Visible;
                    if (MediaFile.Contains("http"))
                    {
                        StoryVideoView.SetVideoURI(Uri.Parse(MediaFile));
                        StoryVideoView.Start();
                    }
                    else
                    {
                        var file = Uri.FromFile(new File(MediaFile));
                        StoryVideoView.SetVideoPath(file.Path);
                        StoryVideoView.Start();
                    }

                    await Task.Delay(500);
                }
                else
                {
                    StoryImageView.Visibility = ViewStates.Visible;
                    StoryVideoView.Visibility = ViewStates.Gone;

                    Glide.With(this).Load(MediaFile).Apply(new RequestOptions()).Into(StoryImageView);

                    // GlideImageLoader.LoadImage(this,story.MediaFile, StoryImageView, ImageStyle.CenterCrop, ImagePlaceholders.Drawable);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemple #29
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
            ImageView image     = FindViewById <ImageView> (Resource.Id.image);
            VideoView videoView = FindViewById <VideoView>(Resource.Id.surfacevideoview);


            //
            // Wire up the take a video button
            //
            Button videoButton = FindViewById <Button> (Resource.Id.takeVideoButton);

            videoButton.Click += delegate
            {
                //
                // The MediaPicker is the class used to
                // invoke the camera and gallery picker
                // for selecting and taking photos
                // and videos
                //
                var picker = new MediaPicker(this);

                // We can check to make sure the device has a camera
                // and supports dealing with video.
                if (!picker.IsCameraAvailable || !picker.VideosSupported)
                {
                    ShowUnsupported();
                    return;
                }

                //
                // TakeVideoAsync is an async API that takes a
                // StoreVideoOptions object with various
                // properties, such as the name and folder to
                // store the resulting video. You can
                // also limit the length of the video
                //
                picker.TakeVideoAsync(new StoreVideoOptions
                {
                    Name          = "MyVideo",
                    Directory     = "MyVideos",
                    DesiredLength = TimeSpan.FromSeconds(10)
                })
                .ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    //
                    // Because TakeVideoAsync returns a Task
                    // we can use ContinueWith to run more code
                    // after the user finishes recording the video
                    //
                    RunOnUiThread(() =>
                    {
                        //
                        // Toggle the visibility of the image and videoviews
                        //
                        image.Visibility     = Android.Views.ViewStates.Gone;
                        videoView.Visibility = Android.Views.ViewStates.Visible;

                        //
                        // Load in the video file
                        //
                        videoView.SetVideoPath(t.Result.Path);

                        //
                        // optional: Handle when the video finishes playing
                        //
                        //videoView.setOnCompletionListener(this);

                        //
                        // Start playing the video
                        //
                        videoView.Start();
                    });
                });
            };

            //
            // Wire up the take a photo button
            //
            Button photoButton = FindViewById <Button> (Resource.Id.takePhotoButton);

            photoButton.Click += delegate
            {
                var picker = new MediaPicker(this);

                if (!picker.IsCameraAvailable || !picker.PhotosSupported)
                {
                    ShowUnsupported();
                    return;
                }

                picker.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    Name      = "test.jpg",
                    Directory = "MediaPickerSample"
                })
                .ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    Bitmap b = BitmapFactory.DecodeFile(t.Result.Path);
                    RunOnUiThread(() =>
                    {
                        //
                        // Toggle the visibility of the image and video views
                        //
                        videoView.Visibility = Android.Views.ViewStates.Gone;
                        image.Visibility     = Android.Views.ViewStates.Visible;

                        //
                        // Display the bitmap
                        //
                        image.SetImageBitmap(b);

                        // Cleanup any resources held by the MediaFile instance
                        t.Result.Dispose();
                    });
                });
            };

            //
            // Wire up the pick a video button
            //
            Button pickVideoButton = FindViewById <Button> (Resource.Id.pickVideoButton);

            pickVideoButton.Click += delegate
            {
                //
                // The MediaPicker is the class used to
                // invoke the camera and gallery picker
                // for selecting and taking photos
                // and videos
                //
                var picker = new MediaPicker(this);

                if (!picker.VideosSupported)
                {
                    ShowUnsupported();
                    return;
                }

                //
                // PickVideoAsync is an async API that invokes
                // the native gallery
                //
                picker.PickVideoAsync()
                .ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    //
                    // Because PickVideoAsync returns a Task
                    // we can use ContinueWith to run more code
                    // after the user finishes recording the video
                    //
                    RunOnUiThread(() =>
                    {
                        //
                        // Toggle the visibility of the image and video views
                        //
                        image.Visibility     = Android.Views.ViewStates.Gone;
                        videoView.Visibility = Android.Views.ViewStates.Visible;

                        //
                        // Load in the video file
                        //
                        videoView.SetVideoPath(t.Result.Path);

                        //
                        // Optional: Handle when the video finishes playing
                        //
                        //videoView.setOnCompletionListener(this);

                        //
                        // Start playing the video
                        //
                        videoView.Start();

                        // Cleanup any resources held by the MediaFile instance
                        t.Result.Dispose();
                    });
                });
            };

            //
            // Wire up the pick a photo button
            //
            Button pickPhotoButton = FindViewById <Button> (Resource.Id.pickPhotoButton);

            pickPhotoButton.Click += delegate
            {
                var picker = new MediaPicker(this);

                if (!picker.PhotosSupported)
                {
                    ShowUnsupported();
                    return;
                }

                picker.PickPhotoAsync()
                .ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    Bitmap b = BitmapFactory.DecodeFile(t.Result.Path);
                    RunOnUiThread(() =>
                    {
                        //
                        // Toggle the visibility of the image and video views
                        //
                        videoView.Visibility = Android.Views.ViewStates.Gone;
                        image.Visibility     = Android.Views.ViewStates.Visible;

                        //
                        // Display the bitmap
                        //
                        image.SetImageBitmap(b);

                        // Cleanup any resources held by the MediaFile instance
                        t.Result.Dispose();
                    });
                });
            };
        }
Exemple #30
0
        //protected override void OnResume()
        //{
        //    base.OnResume();
        //    //VideoView video = FindViewById<VideoView>(Resource.Id.myVideo);
        //    //video.SystemUiVisibility = StatusBarVisibility.Hidden;

        //    //if (!video.IsPlaying)
        //    //{
        //    //    socket.Emit("START");
        //    //    video.Start();
        //    //}
        //}



        //protected override void OnStop()
        //{
        //    base.OnStop();
        //    //var intent = new Intent(this, typeof(MainActivity));
        //    //intent.AddFlags(ActivityFlags.NewTask);
        //    //this.StartActivity(intent);
        //}


        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            //adminComponentName = new ComponentName(this.BaseContext, "AdminReceiver");


            //devicePM = (DevicePolicyManager)GetSystemService(Context.DevicePolicyService);

            ////devicePM.SetLockTaskPackages(adminComponentName, new String[] { "./.AdminReceiver" });

            //devicePM.LockNow();


            Window.AddFlags(WindowManagerFlags.Fullscreen);// | WindowManagerFlags.TurnScreenOn);
            Window.AddFlags(WindowManagerFlags.KeepScreenOn);
            Window.AddFlags(WindowManagerFlags.DismissKeyguard);
            Window.AddFlags(WindowManagerFlags.NotFocusable);
            Window.AddFlags(WindowManagerFlags.TranslucentStatus);


            IntentFilter filter = new IntentFilter(Intent.ActionScreenOff);


            RequestWindowFeature(WindowFeatures.NoTitle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var sp = PreferenceManager.GetDefaultSharedPreferences(this);

            var edit = sp.Edit();

            edit.PutBoolean(PrefKioskMode, true);
            edit.Commit();

            // Get our button from the layout resource,
            // and attach an event to it

            VideoView video = FindViewById <VideoView>(Resource.Id.myVideo);

            video.SystemUiVisibility = StatusBarVisibility.Hidden;

            if (!video.IsPlaying)
            {
                socket.Emit("START");
                video.Start();
            }
            //Window.ClearFlags(WindowManagerFlags.TurnScreenOn);

            //var metrics = Resources.DisplayMetrics;
            //var widthInDp = ConvertPixelsToDp(metrics.WidthPixels);
            //var heightInDp = ConvertPixelsToDp(metrics.HeightPixels);

            //var uri = Android.Net.Uri.Parse("http://192.168.30.193:3000/videos/a.mp4");
            //video.SetVideoURI(uri);


            //string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyVideos);
            //string filename = System.IO.Path.Combine(path, "a.mp4");

            //var directories = Directory.EnumerateDirectories("./sdcard/Movies");

            video.SetVideoPath("./sdcard/Movies/a.mp4");


            video.Touch += delegate
            {
                socket.Emit("START");
                video.Start();
                count++;

                //if (count > 50)
                //    this.Finish();
            };

            mediaController = new MediaController(this, true);
            video.SetMediaController(mediaController);

            video.Completion += (object sender, EventArgs e) =>
            {
                video.Start();
                //socket.Emit("START");
                //socket.Emit("RESTART", video.CurrentPosition);
            };

            socket.On("UPDATE", () =>
            {
                socket.Emit("POS", video.CurrentPosition);
            });


            socket.On("START", () =>
            {
                video.Start();
                //video.SeekTo((int)data);
                //socket.Emit("RESTART", video.CurrentPosition);
            });

            //socket.On("primeiro", (data) =>
            //{
            //    primeiro = true;
            //});

            //Console.WriteLine(primeiro);

            socket.On("POS", (data) =>
            {
                if (video.IsPlaying)
                {
                    string[] x = data.ToString().Replace("{", "").Replace("}", "").Replace("\n", "").Replace("\"", "").Split(':');
                    video.SeekTo(int.Parse(x[1]));
                }
            });


            //socket.On("RESTART", (data) =>
            //{
            //    Console.WriteLine(data);
            //    video.Start();
            //    video.SeekTo((int)data);
            //});



            //try
            //{
            //    socket.On(Socket.EVENT_CONNECT, () =>
            //    {
            //        socket.Emit("connection");
            //    });

            //    socket.On(Socket.EVENT_DISCONNECT, () =>
            //    {
            //        socket.Connect();
            //    });


            //}
            //catch (Exception ex)
            //{
            //    Console.Write(ex);
            //}


            //DevicePolicyManager devicePolicyManager = (DevicePolicyManager)GetSystemService(Context.DevicePolicyService);
            //ComponentName demoDeviceAdmin = new ComponentName(this, Java.Lang.Class.FromType(typeof(DeviceAdmin)));
            //Intent intent = new Intent(DevicePolicyManager.ActionAddDeviceAdmin);
            //intent.PutExtra(DevicePolicyManager.ExtraDeviceAdmin, demoDeviceAdmin);
            //intent.PutExtra(DevicePolicyManager.ExtraAddExplanation, "Device administrator");
            //StartActivity(intent);

            StartLockTask();
            SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs));
        }