public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
        {
            nn_surface = new Surface (surface);

            RelativeLayout.LayoutParams l;
            DisplayMetrics metrics = new DisplayMetrics();
            nn_activity.WindowManager.DefaultDisplay.GetMetrics(metrics);
            l = new RelativeLayout.LayoutParams(metrics.HeightPixels, metrics.WidthPixels);
            l.AddRule(LayoutRules.CenterInParent);
            float scale = (metrics.HeightPixels * 1.0f) / (metrics.WidthPixels * 1.0f);
            textureview.ScaleX = scale;
            textureview.LayoutParameters=l;

            try {
                nn_mediaplayer= new MediaPlayer();
                //String uriPath = "android.resource://"+nn_activity.PackageName+"/raw/Tap5050_About";
                nn_mediaplayer.SetDataSource(nn_activity,global::Android.Net.Uri.Parse("android.resource://"+nn_activity.PackageName +"/"+ Resource.Raw.Tap5050_About));
                nn_mediaplayer.SetSurface(nn_surface);
                nn_mediaplayer.Prepare();
                nn_mediaplayer.Prepared+= (object sender, EventArgs e) => {
                    (sender as MediaPlayer).Start ();
                };
                nn_mediaplayer.Completion+= (object sender, EventArgs e) => {
                    (sender as MediaPlayer).SeekTo (0);
                    (sender as MediaPlayer).Pause ();
                };

            }catch(Exception e){
                Toast.MakeText (nn_activity,"Sorry,Can not play the video",ToastLength.Long).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);
			}
		}
Example #3
0
        public BufferPlayer(Surface surface):base(surface)
        {
            format = MediaFormat.CreateVideoFormat("video/avc", 720, 480);


            //these are custom/dependant upon the source of the video
            //**TODO: search for and find them @ runtime. (it is not hard to do), but that
            //can cause a slight delay in initial video rendering.
            var sps = new byte[] { 0, 0, 0, 1, 103, 66, 224, 30, 218, 2, 208, 246, 192, 68, 0, 0, 46, 236, 0, 10, 252, 130, 16 };
            var pps = new byte[] { 0, 0, 0, 1, 104, 206, 60, 128 };

            format.SetByteBuffer("csd-0", Java.Nio.ByteBuffer.Wrap(sps));
            format.SetByteBuffer("csd-1", Java.Nio.ByteBuffer.Wrap(pps));
            format.SetInteger(MediaFormat.KeyMaxInputSize, 720 * 480);//don't need this if you look up the pps/sps?
            Log.Debug(TAG, "format: " + format);
        }
Example #4
0
        public DrawingContext CreateDrawingContext()
        {
            var surface = _view.Holder.Surface;
            if (surface == null)
                throw new InvalidOperationException("Surface isn't available");
            if (_currentSurface != surface)
            {
                _currentSurface = null;
                if (_currentRenderTarget != IntPtr.Zero)
                {
                    MethodTable.Instance.DisposeRenderTarget(_currentRenderTarget);
                    _currentRenderTarget = IntPtr.Zero;
                }

                _currentRenderTarget = MethodTable.Instance.CreateWindowRenderTarget(surface.Handle);
                _currentSurface = surface;
            }
            return new DrawingContext(
                new DrawingContextImpl(MethodTable.Instance.RenderTargetCreateRenderingContext(_currentRenderTarget)));
        }
		//Start the camera preview
		public void startPreview()
		{
			if (null == cameraDevice || !textureView.IsAvailable || null == previewSize) 
				return;

			try {
				SetUpMediaRecorder();
				SurfaceTexture texture = textureView.SurfaceTexture;
				//Assert.IsNotNull(texture);
				texture.SetDefaultBufferSize(previewSize.Width,previewSize.Height);
				previewBuilder = cameraDevice.CreateCaptureRequest(CameraTemplate.Record);
				var surfaces = new List<Surface>();
				var previewSurface = new Surface(texture);
				surfaces.Add(previewSurface);
				previewBuilder.AddTarget(previewSurface);

				var recorderSurface = mediaRecorder.Surface;
				surfaces.Add(recorderSurface);
				previewBuilder.AddTarget(recorderSurface);

				cameraDevice.CreateCaptureSession(surfaces, new PreviewCaptureStateCallback(this),backgroundHandler);

			} catch(CameraAccessException e) {
				e.PrintStackTrace ();
			} catch(IOException e) {
				e.PrintStackTrace ();
			}
		}
Example #6
0
        public static string SAMPLE = dir + "Video_2014_5_6__16_51_56.mp4";//dir+"Video_2014_5_6__16_51_56.mp4";//


        public FilePlayer(Surface surface):base(surface)
        {
            //myContext = context;
        }
		//Start the camera preview
		public void startPreview()
		{
			if (null == camera_device || !texture_view.IsAvailable || null == preview_size) 
				return;

			try {
				SurfaceTexture texture = texture_view.SurfaceTexture;
				//Assert.IsNotNull(texture);
				texture.SetDefaultBufferSize(preview_size.Width,preview_size.Height);
				preview_builder = camera_device.CreateCaptureRequest(CameraTemplate.Preview);
				Surface surface = new Surface(texture);
				var surfaces = new List<Surface>();
				surfaces.Add(surface);
				preview_builder.AddTarget(surface);
				camera_device.CreateCaptureSession(surfaces, new PreviewCaptureStateListener(this),null);


			} catch(CameraAccessException e) {
				e.PrintStackTrace ();
			}
		}
		private void startRecordingVideo() {
			if (null == Activity) 
				return;


			media_recorder = new MediaRecorder ();
			File file = getVideoFile (Activity);
			try {
				//UI
				button_video.SetText (Resource.String.stop);
				is_recording_video = true;

				//Configure the MediaRecorder
				media_recorder.SetAudioSource (AudioSource.Mic);
				media_recorder.SetVideoSource (VideoSource.Surface);
				media_recorder.SetOutputFormat (OutputFormat.Mpeg4);
				media_recorder.SetOutputFile (System.IO.Path.GetFullPath (file.ToString()));
				media_recorder.SetVideoEncodingBitRate (10000000);
				media_recorder.SetVideoFrameRate (30);
				media_recorder.SetVideoSize (1440, 1080);
				media_recorder.SetVideoEncoder (VideoEncoder.H264);
				media_recorder.SetAudioEncoder (AudioEncoder.Aac);
				int rotation = (int)Activity.WindowManager.DefaultDisplay.Rotation;
				int orientation = ORIENTATIONS.Get (rotation);
				media_recorder.SetOrientationHint (orientation);
				media_recorder.Prepare ();
				Surface surface = media_recorder.Surface;

				//Set up CaptureRequest
				builder = camera_device.CreateCaptureRequest (CameraTemplate.Record);
				builder.AddTarget (surface);
				var preview_surface = new Surface (texture_view.SurfaceTexture);
				builder.AddTarget (preview_surface);
				var surface_list = new List<Surface>();
				surface_list.Add(surface);
				surface_list.Add(preview_surface);
				camera_device.CreateCaptureSession(surface_list,new RecordingCaptureStateListener(this),null);

			} catch (IOException e) {
				e.PrintStackTrace ();
			} catch (CameraAccessException e) {
				e.PrintStackTrace ();
			} catch (IllegalStateException e) {
				e.PrintStackTrace ();
			}

		}
Example #9
0
 public void OnDrawnToSurface(Surface surface)
 {
     // Do nothing.
 }
Example #10
0
 public void Release()
 {
     _rendererBuilder.Cancel();
     _rendererBuildingState = RendererBuildingStateIdle;
     _surface = null;
     _player.Release();
 }
Example #11
0
        //protected Context myContext;

        protected Player(Surface surf) { surface = surf; }
Example #12
0
 public void BlockingClearSurface()
 {
     _surface = null;
     PushSurface(true);
 }
        public bool OnSurfaceTextureDestroyed(SurfaceTexture surface)
        {
            if (nn_mediaplayer != null) {
                nn_mediaplayer.Release();
                nn_mediaplayer = null;
            }

            if (nn_surface != null) {
                nn_surface.Release();
                nn_surface= null;
            }
            return true;
        }
        internal void CreateCameraPreviewSession()
        {
            try
            {
                // We configure the size of default buffer to be the size of camera preview we want.
                _surface.SetDefaultBufferSize(_previewSize.Width, _previewSize.Height);

                // This is the output Surface we need to start preview.
                var surface = new Surface(_surface);

                // We set up a CaptureRequest.Builder with the output Surface.
                _previewRequestBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
                _previewRequestBuilder.AddTarget(surface);

                // Here, we create a CameraCaptureSession for camera preview.
                CameraDevice.CreateCaptureSession(new List<Surface> { surface, _imageReader.Surface }, _captureStateCallback, null);
            }
            catch { }
        }
		/// <summary>
		/// Starts the camera previe
		/// </summary>
		private void StartPreview()
		{
			if (mCameraDevice == null || !mTextureView.IsAvailable || mPreviewSize == null) {
				return;
			}
			try 
			{
				SurfaceTexture texture = mTextureView.SurfaceTexture;
				System.Diagnostics.Debug.Assert( texture != null );

				// We configure the size of the default buffer to be the size of the camera preview we want
				texture.SetDefaultBufferSize(mPreviewSize.Width, mPreviewSize.Height);

				// This is the output Surface we need to start the preview
				Surface surface = new Surface(texture);

				// We set up a CaptureRequest.Builder with the output Surface
				mPreviewBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
				mPreviewBuilder.AddTarget(surface);

				// Here, we create a CameraCaptureSession for camera preview.
				mCameraDevice.CreateCaptureSession(new List<Surface>() { surface }, 
					new CameraCaptureStateListener() 
					{ 
						OnConfigureFailedAction = (CameraCaptureSession session) => 
						{
							Activity activity = Activity;
							if (activity != null)
							{
								Toast.MakeText(activity, "Failed", ToastLength.Short).Show();
							}
						},
						OnConfiguredAction = (CameraCaptureSession session) =>
						{
							mPreviewSession = session;
							UpdatePreview ();
						}
					},
					null);


			}
			catch (Exception ex) {
				Log.WriteLine (LogPriority.Info, "Camera2BasicFragment", ex.StackTrace);
			}
		}
Example #16
0
        private void StartPreview()
        {
            if (mCameraDevice == null || !mTextureView.IsAvailable || mPreviewSize == null)
            {
                return;
            }
            try
            {
                SurfaceTexture texture = mTextureView.SurfaceTexture;
                System.Diagnostics.Debug.Assert( texture != null);

                texture.SetDefaultBufferSize(mPreviewSize.Width, mPreviewSize.Height);

                Surface surface = new Surface(texture);

                mPreviewBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.Preview);

                mPreviewBuilder.AddTarget(surface);

                mCameraDevice.CreateCaptureSession(
                    new List<Surface>() {surface},

                    new CameraCaptureStateListener()
                    {
                        OnConfigureFailedAction = (CameraCaptureSession session) =>
                        {
                            Activity activity = Activity;

                            if(activity != null)
                            {
                                Toast.MakeText(activity, "Failed", ToastLength.Short).Show();
                            }
                        },
                        OnConfiguredAction = (CameraCaptureSession session) =>
                        {
                            mPreviewSession = session;
                            UpdatePreview ();
                        }
                    },
                    null);
            }
            catch(CameraAccessException ex)
            {
                Log.WriteLine (LogPriority.Info, "CameraFragment", ex.StackTrace);
            }
        }
Example #17
0
 public FilePlayer2(Surface surface):base(surface)
 {
 }