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

			// Carega o layout "main" na view principal
			SetContentView (Resource.Layout.Main);

			// Pega o botão do recurso de layout e coloca um evento nele
			Button button = FindViewById<Button> (Resource.Id.button);

			vv = FindViewById<VideoView> (Resource.Id.video_view);
			pb = FindViewById<ProgressBar> (Resource.Id.progress_bar);
			MediaController mc = new MediaController(this);
			mp = new MediaPlayer ();

			pb.SetOnTouchListener (this);

			var uri = Android.Net.Uri.Parse ("http://3gpfind.com/vid/load/Movie%20Trailer/Predators(3gpfind.com).3gp");
			vv.SetOnPreparedListener (this);
			vv.SetVideoURI(uri);
			vv.SetMediaController(mc);
			mc.SetMediaPlayer(vv);
			mc.SetAnchorView(vv);

			button.Click += delegate {
				mc.Show();
				if (!ready)
				{
					holder = vv.Holder;
					holder.SetType (SurfaceType.PushBuffers);
					holder.AddCallback(this);
					mp.SetDataSource(this, uri);
					mp.SetOnPreparedListener(this);
					mp.Prepare();
					ready = true;
				}

				mp.Start();
//				vv.Start();

				Toast.MakeText (this, "Video Started", ToastLength.Short).Show ();
			};
		}
		private void PlayVideo(SurfaceTexture surfaceTexture)
		{
			DoCleanUp();
			try
			{

				path = "http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8";
				if (path == "")
				{
					// Tell the user to provide a media file URL.
					Toast.MakeText(this, "Please edit MediaPlayerDemo_setSurface Activity, " + "and set the path variable to your media file path." + " Your media file must be stored on sdcard.", ToastLength.Long).Show();
					return;
				}
				// Create a new media player and set the listeners
				mMediaPlayer = new MediaPlayer(this, true);
				mMediaPlayer.SetDataSource(path);
				if (surf == null)
				{
					surf = new Surface (surfaceTexture);
				}
				mMediaPlayer.SetSurface(surf);
				mMediaPlayer.PrepareAsync();
				mMediaPlayer.SetOnBufferingUpdateListener(this);
				mMediaPlayer.SetOnCompletionListener(this);
				mMediaPlayer.SetOnPreparedListener(this);
				VolumeControlStream = Stream.Music;

			}
			catch (Exception e)
			{
				Log.Error(TAG, "error: " + e.Message, e);
			}
		}
예제 #3
0
 public AndroidMusic(AssetFileDescriptor afd)
 {
     this.mp = new MediaPlayer ();
     try {
         mp.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length);
         mp.Prepare();
         isPrepared = true;
         mp.SetOnCompletionListener(this);
         mp.SetOnSeekCompleteListener(this);
         mp.SetOnPreparedListener(this);
         mp.SetOnVideoSizeChangedListener(this);
     } catch {
         throw new ApplicationException("Couldn't load music");
     }
 }
예제 #4
0
        void CreateMediaPlayerIfNeeded()
        {
            if (mediaPlayer != null)
            {
                mediaPlayer.Reset();
                return;
            }

            mediaPlayer = new Android.Media.MediaPlayer();
            mediaPlayer.SetWakeMode(Context.ApplicationContext, WakeLockFlags.Partial);
            mediaPlayer.SetOnPreparedListener(this);
            mediaPlayer.SetOnCompletionListener(this);
            mediaPlayer.SetOnErrorListener(this);
            mediaPlayer.SetOnSeekCompleteListener(this);
        }
예제 #5
0
        public AndroidMusic(AssetFileDescriptor assetDescriptor)
        {
            mediaPlayer = new MediaPlayer();
            try
            {
                mediaPlayer.SetDataSource(assetDescriptor.FileDescriptor,
                                          assetDescriptor.StartOffset,
                                          assetDescriptor.Length);
                mediaPlayer.Prepare();
                isPrepared = true;
                mediaPlayer.SetOnCompletionListener(this);
                mediaPlayer.SetOnSeekCompleteListener(this);
                mediaPlayer.SetOnPreparedListener(this);
                mediaPlayer.SetOnVideoSizeChangedListener(this);

            }
            catch (Exception e)
            {
                throw new SystemException("Couldn't load music");
            }
        }
예제 #6
0
        private void InitializePlayer()
        {
            _player = new AndroidMediaPlayer();
            var surfaceView = RenderSurface as SurfaceView;

            if (_hasValidHolder)
            {
                _player.SetDisplay(surfaceView.Holder);
                _player.SetScreenOnWhilePlaying(true);
            }
            else
            {
                surfaceView.Holder.AddCallback(this);
            }

            _player.SetOnErrorListener(this);
            _player.SetOnPreparedListener(this);
            _player.SetOnSeekCompleteListener(this);
            _player.SetOnBufferingUpdateListener(this);

            PlaybackSession.PlaybackStateChanged -= OnStatusChanged;
            PlaybackSession.PlaybackStateChanged += OnStatusChanged;
        }
예제 #7
0
		void CreateMediaPlayerIfNeeded ()
		{
			LogHelper.Debug (Tag, "createMediaPlayerIfNeeded. needed? ", (mediaPlayer==null));
			if (mediaPlayer == null) {
				mediaPlayer = new MediaPlayer ();

				mediaPlayer.SetWakeMode (service.ApplicationContext,
					Android.OS.WakeLockFlags.Partial);

				mediaPlayer.SetOnPreparedListener (this);
				mediaPlayer.SetOnCompletionListener (this);
				mediaPlayer.SetOnErrorListener (this);
				mediaPlayer.SetOnSeekCompleteListener (this);
			} else {
				mediaPlayer.Reset ();
			}
		}
		private void PlayVideo(int Media)
		{
			DoCleanUp();
			try
			{

				switch (Media)
				{
				case LOCAL_VIDEO:
					//                
					//				 * TODO: Set the path variable to a local media file path.
					//				 
					path = "http://172.16.101.100:81/video/123.mp4";
					if (path == "")
					{
						// Tell the user to provide a media file URL.
						Toast.MakeText(this, "Please edit MediaPlayerDemo_Video Activity, " + "and set the path variable to your media file path." + " Your media file must be stored on sdcard.", ToastLength.Long).Show();
						return;
					}
					break;
				case STREAM_VIDEO:
					//                
					//				 * TODO: Set path variable to progressive streamable mp4 or
					//				 * 3gpp format URL. Http protocol should be used.
					//				 * Mediaplayer can only play "progressive streamable
					//				 * contents" which basically means: 1. the movie atom has to
					//				 * precede all the media data atoms. 2. The clip has to be
					//				 * reasonably interleaved.
					//				 * 
					//				 
						path = "http://172.16.101.100:81/video/123.mp4";
					if (path == "")
					{
						// Tell the user to provide a media file URL.
						Toast.MakeText(this, "Please edit MediaPlayerDemo_Video Activity," + " and set the path variable to your media file URL.", ToastLength.Long).Show();
						return;
					}

					break;

				}

				// Create a new media player and set the listeners
				mMediaPlayer = new MediaPlayer(this);
				mMediaPlayer.SetDataSource(path);
				mMediaPlayer.SetDisplay(holder);
				mMediaPlayer.PrepareAsync();
				mMediaPlayer.SetOnBufferingUpdateListener(this);
				mMediaPlayer.SetOnCompletionListener(this);
				mMediaPlayer.SetOnPreparedListener(this);
				mMediaPlayer.SetOnVideoSizeChangedListener(this);
				VolumeControlStream = Stream.Music;

			}
			catch (Exception e)
			{
				Log.Error(TAG, "error: " + e.Message, e);
			}
		}
예제 #9
0
        public void InitMusicPlayer()
        {
            _appSettingsHelper = new AppSettingsHelper();
            _player = new MediaPlayer();
            _wifiLock = ((WifiManager)GetSystemService(WifiService)).CreateWifiLock(WifiMode.Full, "playerLock");

            _player.SetWakeMode(ApplicationContext, WakeLockFlags.Partial);
            _player.SetAudioStreamType(Stream.Music);
            _player.SetOnPreparedListener(this);
            _player.SetOnCompletionListener(this);
            _player.SetOnErrorListener(this);

            _audioManager = (AudioManager) GetSystemService(AudioService);

            _mediaButtonReceiverComponent = new ComponentName(ApplicationContext,
                Class.FromType(typeof (HeadsetButtonsReceiver)));
            _audioManager.RegisterMediaButtonEventReceiver(_mediaButtonReceiverComponent);
        }
        /// <summary>
        /// Intializes the player.
        /// </summary>
        private void InitializePlayer ()
        {
            mediaPlayer = new MediaPlayer ();

            //Tell our player to sream music
            mediaPlayer.SetAudioStreamType (Stream.Music);

            //Wake mode will be partial to keep the CPU still running under lock screen
            mediaPlayer.SetWakeMode (ApplicationContext, WakeLockFlags.Partial);

            mediaPlayer.SetOnBufferingUpdateListener (this);
            mediaPlayer.SetOnCompletionListener (this);
            mediaPlayer.SetOnErrorListener (this);
            mediaPlayer.SetOnPreparedListener (this);
        }