Adjust the speed of playing videoview in Android -


i want adjust playback speed control.

  • there + , - buttons increase , decrease playing speed.

  • every time button clicked, speed increase/decrease 0.5 time ( -1 <--> -0.5 <--> 0 <--> 0.5 <--> 1).

  • the speed change in range -2 2.

<framelayout xmlns:android="http://schemas.android.com/apk/res/android"      android:id="@+id/framelayout1"      android:layout_width="fill_parent"      android:layout_height="fill_parent"      android:layout_weight="1" >  	      <relativelayout          android:layout_width="fill_parent"          android:layout_height="fill_parent" >            <videoview              android:id="@+id/item_video"              android:layout_width="fill_parent"              android:layout_height="fill_parent"                android:layout_alignparentbottom="true"       		android:layout_alignparenttop="true"       		android:layout_alignparentleft="true"         		android:layout_alignparentright="true"                         android:layout_centerinparent="true"              android:layout_weight="1" />      </relativelayout>        <progressbar          android:id="@+id/progressvideo"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_centerinparent="true"          android:layout_gravity="center"          android:indeterminate="true" />        <imagebutton          android:id="@+id/btnvirtualplay"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_gravity="center"          android:background="@android:color/transparent"          android:onclick="onclick"          android:scaletype="centerinside"          android:src="@drawable/play_transparent_icon" />        <imagebutton          android:id="@+id/btnplay"          android:layout_width="50dp"          android:layout_height="50dp"          android:layout_gravity="center"          android:background="@android:color/transparent"          android:onclick="onclick"          android:scaletype="centerinside"          android:src="@drawable/pause_big_icon" />        <relativelayout          android:id="@+id/relativelayout1"          android:layout_width="match_parent"          android:layout_height="match_parent" >            <relativelayout              android:id="@+id/rlvideobar"              android:layout_width="match_parent"              android:layout_height="wrap_content"              android:layout_alignparentbottom="true"              android:layout_alignparentleft="true"              android:background="@color/black_70" >                <imagebutton                  android:id="@+id/btnplayvideo"                  android:layout_width="20dp"                  android:layout_height="20dp"                  android:layout_alignparentleft="true"                  android:layout_alignparenttop="true"                  android:layout_centervertical="true"                  android:background="@android:color/transparent"                  android:layout_marginleft ="5dp"                  android:onclick="onclick"                  android:scaletype="centerinside"                  android:src="@drawable/pause_video_icon" />                <seekbar                  android:id="@+id/sbtimer"                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:layout_centervertical="true"                  android:layout_toleftof="@+id/tvendtime"                  android:layout_torightof="@+id/tvbegintime" />                <imagebutton                  android:id="@+id/btnzoomin"                  android:layout_width="20dp"                  android:layout_height="20dp"                  android:layout_alignparentright="true"                  android:layout_alignparenttop="true"                  android:layout_centervertical="true"                  android:layout_marginright="8dp"                  android:background="@android:color/transparent"                  android:onclick="onclick"                  android:scaletype="centerinside"                  android:src="@drawable/zoom_out_icon"/>                <textview                  android:id="@+id/tvbegintime"                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:layout_centervertical="true"                  android:layout_marginleft="5dp"                  android:layout_torightof="@+id/btnplayvideo"                  android:text="00:00"                  android:textcolor="@color/white"                  android:textsize="10dp" />                <textview                  android:id="@+id/tvendtime"                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:layout_centervertical="true"                  android:layout_marginright="14dp"                  android:layout_toleftof="@+id/btnzoomin"                  android:text="00:00"                  android:textcolor="@color/white"                  android:textsize="10dp" />          </relativelayout>      </relativelayout>    </framelayout>

void addvideolayout() {  		mvideoview = courseinfofragment.this.getactivity().getlayoutinflater().inflate(r.layout.my_course_info_video, null);		  		mcourseimageorvideo.addview(mvideoview);  		  		videoview = (videoview) mvideoview.findviewbyid(r.id.item_video);  		btnplay = (imagebutton) mvideoview.findviewbyid(r.id.btnplay);  		btnplayvideo = (imagebutton) mvideoview.findviewbyid(r.id.btnplayvideo);  		btnzoom = (imagebutton) mvideoview.findviewbyid(r.id.btnzoomin);  		mprogressbar = (progressbar) mvideoview.findviewbyid( r.id.progressvideo);  		  		rlvideobar = (relativelayout) mvideoview.findviewbyid(r.id.rlvideobar);  		mseekbar = (seekbar) mvideoview.findviewbyid(r.id.sbtimer);  		tvcurrenttime = (textview) mvideoview.findviewbyid(r.id.tvbegintime);  		tvtimetotal = (textview) mvideoview.findviewbyid(r.id.tvendtime);  		  		// use show background video  		drawable drawable = new bitmapdrawable(getresources(),bitmap);  		if (build.version.sdk_int < build.version_codes.jelly_bean){  			videoview.setbackgrounddrawable(drawable);  		} else {  			videoview.setbackground(drawable);  		}  		  		// use hide progressbar  		mprogressbar.setvisibility( view.invisible );    		// use hide virtualplaybuttonimage  		imagebutton btnvirtualplay = (imagebutton) mvideoview.findviewbyid(r.id.btnvirtualplay);  		btnvirtualplay.setvisibility(view.invisible);  		  		// listeners  		mseekbar.setonseekbarchangelistener(this); // important  		// mediaplayer  		utils = new time();  		  		misvideofirst = false;  		  		btnplay.setonclicklistener(new onclicklistener() {  			  			@override  			public void onclick(view v) {  				// todo auto-generated method stub  				onplaybuttonlistener();   			}  		});  		  		btnplayvideo.setonclicklistener(new onclicklistener() {  			  			@override  			public void onclick(view v) {  				// todo auto-generated method stub  				onplaybuttonlistener();   			}  		});  				  		btnzoom.setonclicklistener(new onclicklistener() {  			  			@override  			public void onclick(view v) {  				// todo auto-generated method stub  			}  		});  		  		videoview.setontouchlistener(videoviewtouchlistener);  		videoview.setoncompletionlistener( oncompletionlistener );  		videoview.setonpreparedlistener( onpreparedlistener );  		videoview.setonerrorlistener(new onerrorlistener() {    			@override  			public boolean onerror(mediaplayer mp, int what, int extra) {  				if (!network.isonline(courseinfofragment.this.getactivity().getapplicationcontext())) {    					networkalertview.shownetworkdialog(courseinfofragment.this.getactivity(), getresources().getstring(r.string.vcampus_title_network_connection),  					        getresources().getstring(r.string.vcampus_message_network_connection), false);  				}  				return true;  			}  		});  		  		// use hide video tab , video bar object  		setvideobarstatus(rlvideobar, false);  		misdisplayedvideobar = true;  	}	  		  	// use play video server	  	void seturiforvideoview(videoview _videoview, uri uri)  	{  		if(!misvideofirst)  		{  		mprogressbar.setvisibility(view.visible);  		misvideofirst = true;  		_videoview.setvideouri(uri);		                                                              		seekupdation();	  		}  		  	}		  			  	// use play/pause video  	@suppresslint("newapi")  	@suppresswarnings("deprecation")  	void onplaybuttonlistener() {  		// use check playing  		if (videoview.isplaying()) {  			btnplay.setimageresource(r.drawable.pause_big_icon);  			btnplay.setvisibility(view.visible);    			// use changing button image pause button  			btnplayvideo.setimageresource(r.drawable.pause_video_icon);    			videoview.pause();  		} else {  						  			btnplay.setimageresource(r.drawable.play_big_icon);  			btnplay.setvisibility(view.invisible);    			// use changing button image play button  			btnplayvideo.setimageresource(r.drawable.play_video_icon);  			if (build.version.sdk_int < build.version_codes.jelly_bean){  				videoview.setbackgrounddrawable(null);  			} else {  				videoview.setbackground(null);  			}  			  			seturiforvideoview(videoview, muri);  			videoview.start();  			  		}  	}					  			  	// loading use onpreparedlistener  	protected mediaplayer.onpreparedlistener onpreparedlistener = new mediaplayer.onpreparedlistener() {    		@override  		public void onprepared(mediaplayer mediaplayer) {			  			mprogressbar.setvisibility( view.gone );							  			btnplay.setimageresource(r.drawable.pause_big_icon);  			btnplay.setvisibility(view.invisible);  		}  	};	  	  	protected mediaplayer.oncompletionlistener oncompletionlistener = new mediaplayer.oncompletionlistener() {  		@suppresslint("newapi")  		@suppresswarnings("deprecation")  		@override  		public void oncompletion(mediaplayer mediaplayer) {  			btnplay.setimageresource(r.drawable.pause_big_icon);  			btnplay.setvisibility(view.visible);    			// use changing button image pause button  			btnplayvideo.setimageresource(r.drawable.pause_video_icon);  			  			// use set background video when completion  			drawable drawable = new bitmapdrawable(getresources(),bitmap);  			if (build.version.sdk_int < build.version_codes.jelly_bean){  				videoview.setbackgrounddrawable(drawable);  			} else {  				videoview.setbackground(drawable);  			}  		  		}  	};		  			  	// use listener touch video view event  	private ontouchlistener videoviewtouchlistener = new ontouchlistener() {    		@override  		public boolean ontouch(view v, motionevent event) {  			// use hide/show video tab , video bar object  			if (!misdisplayedvideobar) {  				setvideobarstatus(rlvideobar, false);    				misdisplayedvideobar = true;  			} else {  				setvideobarstatus(rlvideobar, true);    				misdisplayedvideobar = false;  			}    			return false;  		}  	};			  			  	// use set hide/show status player controls  	public static void setvideobarstatus(view _barview, boolean _status) {  		if (_status) {  			_barview.setvisibility(view.visible);	  		} else {  			_barview.setvisibility(view.invisible);  		}  	}	  	  	public void seekupdation() {    		long mcurrentduration = videoview.getcurrentposition();  		long totalduration = videoview.getduration();    		// use set video timer  		tvcurrenttime.settext("" + utils.millisecondstotimer(mcurrentduration));  		tvtimetotal.settext("" + utils.millisecondstotimer(totalduration));    		// updating progress bar  		int progress = (int) (utils.getprogresspercentage(mcurrentduration, totalduration));  		mseekbar.setprogress(progress);    		mhandler.postdelayed(mupdatetimetask, 1000);  	}  	  	@override  	public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) {  		// todo auto-generated method stub    	}    	@override  	public void onstarttrackingtouch(seekbar seekbar) {  		// todo auto-generated method stub  		mhandler.removecallbacks(mupdatetimetask);  	}    	@override  	public void onstoptrackingtouch(seekbar seekbar) {  		// todo auto-generated method stub  		mhandler.removecallbacks(mupdatetimetask);  		  		int totalduration = videoview.getduration();  		int currentposition = utils.progresstotimer(seekbar.getprogress(), totalduration);    		// forward or backward seconds  		videoview.seekto(currentposition);    		// update timer progress again  		updateprogressbar();    	}		  			  	/**  	 * update timer on seekbar  	 * */  	public void updateprogressbar() {  		mhandler.postdelayed(mupdatetimetask, 100);  	}    	runnable mupdatetimetask = new runnable() {  		@override  		public void run() {  			seekupdation();  		}  	};			


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -