Example #1
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");
     }
 }
Example #2
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");
            }
        }
		public void OnPrepared (MediaPlayer mp)
		{
			mp.Looping = true;
			int h = mp.VideoHeight;
			int w = mp.VideoWidth;

			mp.SetOnVideoSizeChangedListener (this);
			mp.SetOnBufferingUpdateListener (this);
			mp.SetOnSeekCompleteListener (this);
			mp.SetOnCompletionListener (this);

			int time = vv.Duration;
			int time_elapsed = vv.CurrentPosition;
			pb.Progress = time_elapsed;

			var timer = new CountDown (time, 500);
			timer.Tick += (long millisUntilFinished) => {
				float a = vv.CurrentPosition;
				float b = vv.Duration;

				pb.Progress = (int)(a/b*100);
			};
			timer.Finish += () => {
				Toast.MakeText (this, "Timer Finished", ToastLength.Short).Show ();
			};

			Toast.MakeText (this, "Video Prepared", ToastLength.Short).Show ();
		}
		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);
			}
		}