Home > Mobile >  SurfaceView loading the video, and the activity of a layout
SurfaceView loading the video, and the activity of a layout

Time:09-23

SurfaceView loading the video, and the activity of a layout is how to solve the refer to

CodePudding user response:

Why is this

CodePudding user response:

I also don't understand the SurfaceView seemed to put this activity hollowed out a direct display screens

CodePudding user response:

When the code is the draw on this wrong

CodePudding user response:

 public class VideoView extends AbsView {
Private Button bt;//used to start and stop button
Private SurfaceView pView;//drawing container object, used for the video display on the screen
private String url;//video broadcast address
Private MediaPlayer MediaPlayer.//player controls
Private int postSize;//save the righteous broadcast video size
Private SeekBar SeekBar.//progress bar control
Private Boolean flag=true;//is used to determine whether video playback in
Private RelativeLayout rl.
Private Boolean display;//whether to show other buttons
Private View View;//ProgressBar
Private upDateSeekBar update;//update the progress bar with

Public VideoView Context (Context) {
Super (context);
init();//initialization data
Url="http://flv2.bn.netease.com/videolib3/1607/12/QpHhw9884/SD/QpHhw9884-mobile.mp4";//video broadcast address
SetListener ();//bind related events
}

@ Override
Public int layoutResId () {
Return R.l ayout. View_video;
}

@ Override
Public void loadData (Object data) {
}

@ Override
Public Boolean isEmpty () {
return false;
}

Private void init () {
mediaPlayer=new MediaPlayer();//create a player object
The update=new upDateSeekBar ();//update the progress bar object creation
Seekbar=(seekbar) the findViewById (R.i d.s eekbar);//the progress bar
Bt=(Button) the findViewById (R.i d.p lay);
Bt. SetEnabled (false);//just come in, set its not click
PView=(SurfaceView) the findViewById (R.i d.m SurfaceView);
PView. GetHolder (). SetType (SurfaceHolder. SURFACE_TYPE_PUSH_BUFFERS);//no buffer
PView. GetHolder (). SetKeepScreenOn (true);//to keep the screen highlighting
PView. GetHolder (). The addCallback (new surFaceView ());//set to monitor events
Rl=(RelativeLayout) the findViewById (R.i d.r l2);
View=the findViewById (R.i d.p b);

Bt. SetVisibility (View. GONE);
Rl. SetVisibility (View. GONE);
}

Class PlayMovie extends Thread {//play video Thread

Int post=0;

Public PlayMovie (int post) {
This. Post=post;

}

@ Override
Public void the run () {
The Message the Message=Message. Obtain ();
Try {
Log. I (" HCK runrun ", "" + url);
MediaPlayer. Reset ();//reply player the default
MediaPlayer. SetDataSource (url);//set the playback path
MediaPlayer. SetAudioStreamType (AudioManager. STREAM_MUSIC);
MediaPlayer. SetDisplay (pView getHolder ());//to display video on SurfaceView
MediaPlayer. SetOnPreparedListener (new Ok (post));//set to monitor events
MediaPlayer. Prepare ();//to play
} the catch (Exception e) {
Message. What=2;
The e (" HCK ", e. oString ());
}

Super. The run ();
}
}

The class Ok implements OnPreparedListener {
Int postSize;

Public Ok (int postSize) {
Enclosing postSize=postSize;
}

@ Override
Public void onPrepared (MediaPlayer mp) {
The Log i. (" HCK ", "play");
Log. I (+ postSize "HCK", "post");
The setVisibility (view. GONE);//preparation is completed, hidden controls
Bt. SetVisibility (View. GONE);
Rl. SetVisibility (View. GONE);
Bt. SetEnabled (true);
The display=false;
If (mediaPlayer!=null) {
MediaPlayer. Start ();//start playing video
} else {
return;
}
If (postSize & gt; 0) {//midway stopped (activity call pase method, not the user click the stop button), jump to the stop position when start playing
The Log i. (" HCK ", "seekTo");
MediaPlayer. SeekTo (postSize);//jump to postSize size location to play
}
New Thread (update). The start ();//start a thread, update the progress bar
}
}

Private class surFaceView implements the Callback {//binding listening in on the event

@ Override
Public void surfaceChanged (SurfaceHolder holder, int format, int width,
{int height)
}

@ Override
Public void surfaceCreated (SurfaceHolder holder) {//create a call after the completion of the
If (postSize & gt; 0 & amp; & The url!=null) {//that stopped the activity call pase method, jump to the stop position play
New PlayMovie (postSize.) start ();
flag=true;
Int sMax=seekbar. GetMax ();
Int mMax=mediaPlayer. GetDuration ();
Seekbar. SetProgress (postSize * sMax/mMax);
PostSize=0;
The setVisibility (view. GONE);
} else {
New PlayMovie (0). The start ();//that is my first start playing
}
}

@ Override
Public void surfaceDestroyed (SurfaceHolder holder) {//the activity call pase method, save the current playback position
If (mediaPlayer!=null & amp; & MediaPlayer. IsPlaying ()) {
PostSize=mediaPlayer. GetCurrentPosition ();
MediaPlayer. Stop ();
flag=false;
view.setVisibility(View.VISIBLE);
}
}
}

Private void setListener () {
MediaPlayer
SetOnBufferingUpdateListener (new MediaPlayer. OnBufferingUpdateListener () {
@ Override
Public void onBufferingUpdate (MediaPlayer mp, int percent) {
}
});

MediaPlayer
SetOnCompletionListener (new MediaPlayer. OnCompletionListener () {//video broadcast complete
@ Override
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related