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;
                }
            }
            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();
            }
        }
Beispiel #2
0
        public AudioView(Context context, Audio audio, string path, ViewerScreen docView) : base(context)
        {
            _audio     = audio;
            _basePath  = path;
            _docView   = docView;
            _audioView = new Android.Widget.VideoView(context);

            ViewGroup.LayoutParams param = new ViewGroup.LayoutParams(1, 1);
            _audioView.LayoutParameters = param;

            if (!File.Exists(System.IO.Path.Combine(_basePath, _audio.Link)))
            {
                return;
            }

            _audioView.SetVideoPath(System.IO.Path.Combine(_basePath, _audio.Link));

            var time = _audioView.CurrentPosition;

            this.AddView(_audioView);

            _audioView.RequestFocus();

            //playstopclick
            if (_audio.PlayStopClick)
            {
                this.Click += (sender, e) =>
                {
                    this.PlayStop();
                };
            }

            //autoplay
            if (this._audio.Autoplay)
            {
                //_audioView.Prepared -= Autoplay;
                //_audioView.Prepared += Autoplay;
                _audioView.Prepared += (sender, e) =>
                {
                    _isReady = true;
                };
            }

            //loop
            if (_audio.Loop)
            {
                _audioView.Completion += (sender, e) =>
                {
                    _audioView.Start();
                };
            }
        }
Beispiel #3
0
 public void Play()
 {
     try
     {
         if (_audioView != null)
         {
             _audioView.Start();
         }
     }
     catch (Exception ex)
     {
         Log.Error("AudioView(Play)", ex.Message);
     }
 }
Beispiel #4
0
        public void SurfaceCreated(ISurfaceHolder holder)
        {
            if (_view.Url.StartsWith("http://") || _view.Url.StartsWith("https://"))
            {
                _videoview.SetVideoURI(Android.Net.Uri.Parse(_view.Url));
            }
            else
            {
                _videoview.SetVideoPath(_view.Url);
            }

            _videoview.Start();

            _controller.Show(3000);
        }
        void PlayVideo(object sender, EventArgs arg)
        {
            //Start that video!!!
            var activity = Context as Activity;

            activity.RunOnUiThread(() =>
            {
                if (playFromAssets)
                {
                    player.Prepare();
                    player.Start();
                }
                else
                {
                    videoView.Start();
                }
            });
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            this.Window.AddFlags(WindowManagerFlags.Fullscreen);

            _video    = JsonConvert.DeserializeObject <Video>(Intent.GetStringExtra("video"));
            _basePath = Intent.GetStringExtra("path");

            Android.Widget.VideoView videoView = new Android.Widget.VideoView(this);

            ViewGroup.LayoutParams param = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);

            videoView.LayoutParameters = param;
            //var uri = Android.Net.Uri.Parse(System.IO.Path.Combine(path, _video.Link));

            if (_video.Link.StartsWith("http:"))
            {
                videoView.SetVideoURI(Android.Net.Uri.Parse(_video.Link));
                //_videoView.SetBackgroundColor(Color.Fuchsia);
            }
            else
            {
                videoView.SetVideoPath(System.IO.Path.Combine(_basePath, _video.Link));
            }

            //videoView.SetBackgroundColor(Color.Black);
            _contentView.SetBackgroundColor(Color.Black);

            MediaController mc = new MediaController(this);

            videoView.SetMediaController(mc);
            mc.RequestFocus();

            _contentView.AddView(videoView);

            videoView.Start();
        }
Beispiel #7
0
        public void Play()
        {
            try
            {
                if (_videoView != null)
                {
                    this.Show();

                    _videoView.SeekTo(0);
                    _videoView.Start();
                    //_videoView.RequestFocus();

                    if (OnStart != null)
                    {
                        OnStart();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("VideoView(Play)", ex.Message);
            }
        }
Beispiel #8
0
        public VideoView(Context context, Video video, string path, ViewerScreen docView) : base(context)
        {
            _video    = video;
            _basePath = path;
            _docView  = docView;
            //this.SetBackgroundColor(Color.Aqua);

            View.Inflate(this.Context, Resource.Layout.VideoView, this);



            try
            {
                _videoView = FindViewById <Android.Widget.VideoView>(Resource.Id.videoView);
                _btnFull   = FindViewById <ImageButton>(Resource.Id.btnFull);

                if (video.Link != "")
                {
                    if (!File.Exists(System.IO.Path.Combine(_basePath, _video.Link)))
                    {
                        return;
                    }

                    _videoView.SetVideoPath(System.IO.Path.Combine(_basePath, _video.Link));
                }
                else if (_video.UrlStream != "")
                {
                    _videoView.SetVideoURI(Android.Net.Uri.Parse(_video.UrlStream));
                }

                /*MediaController mc = new MediaController(context);
                 * mc.SetMediaPlayer(_videoView);
                 * mc.SetAnchorView(_videoView);
                 *
                 * _videoView.SetMediaController(mc);*/
                _videoView.RequestFocus();
            }
            catch (Exception ex)
            {
                Utils.WriteLog("Errore video", ex.Message);
                return;
            }

            _videoView.Error += (sender, e) =>
            {
                return;
            };

            //playstopclick
            if (this._video.PlayStopClick)
            {
                this.Click += (sender, e) =>
                {
                    this.PlayStop();
                };
            }

            if (_video.Fullscreen)
            {
                _btnFull.Click += (sender, e) =>
                {
                    Intent i = new Intent();
                    i.SetClass(this.Context, typeof(VideoViewScreen));

                    i.PutExtra("path", _basePath);
                    i.PutExtra("video", JsonConvert.SerializeObject(_video));
                    //ActivitiesBringe.SetObject(zoom);
                    this.Stop();
                    docView.StartActivity(i);
                };
            }
            else
            {
                _btnFull.Visibility = ViewStates.Invisible;
            }

            //autoplay
            if (this._video.Autoplay)
            {
                //_videoView.Prepared -= Autoplay;
                //_videoView.Prepared += Autoplay;
                _videoView.Prepared += (sender, e) =>
                {
                    _isReady = true;
                };

                if (_video.Delay > 0)
                {
                    this.Hide();
                    _isReady = true;
                }
            }
            else
            {
                this.Hide();
            }

            //loop
            if (_video.Loop)
            {
                _videoView.Completion += (sender, e) =>
                {
                    _videoView.Start();
                };
            }

            //finish
            _videoView.Completion += (sender, e) =>
            {
                if (OnFinish != null)
                {
                    OnFinish();
                }
            };
        }