Basic Learning day11-Multimedia

1 Several ways of computer representation of graphics
Multimedia: (including text, pictures, audio and video)
Graphic size = total pixels of the picture * size of each pixel
Monochrome. Each pixel can represent up to two colors. Only binary bits of length 1 are needed to represent each pixel, then 1/8 byte
16 colors. Each pixel can represent up to 16 colors 0000 - 1111 So just use a binary representation with a length of 4 and each pixel takes up 1/2 byte
256 colors Each pixel can represent up to 256 colors 0000 0000 - 1111 1111 Then just use the binary representation of length 8 so that each pixel takes up 1 byte
24-bit rgb
r 1byte   0-255
g 1byte  0-255
b 1byte 0-255 So one pixel is 3byte
jpg format
Android uses png format

2 Zoom Load Load Large Pictures
09-14 00:59:51.813: E/AndroidRuntime(2128): Caused by: java.lang.OutOfMemoryError
09-14 00:59:51.813: E/dalvikvm-heap(2128): Out of memory on a 30720012-byte allocation.
Use ARGB to represent colors under Android, 4 bytes per pixel
Picture: 2400*3200
Mobile phone: 320*480
Wide zoom: 7
High zoom: 6
Questions to consider (1) Dynamic resolution of the picture
(2) Dynamic acquisition of mobile phone resolution

Implementation Steps (***)
(1) Get the width and height of the mobile phone
\
(2) Get the width and height of the picture
\
(3) Calculate the zoom ratio

(4) Display pictures in zoom ratio

3 Create a copy of the original
The steps are as follows

4 Graphic processing api
[1] Rotation
matrix.setRotate(degrees, srcBitmap.getWidth()/2, srcBitmap.getHeight()/2);
[2] Zoom
matrix.setScale(0.5f, 0.5f);
[3] Displacement
matrix.setTranslate(20, 0);
[4] Shadow effect

[5] Mirror Effect

5 small drawing board cases
The main code is as follows
`	`
```//[4] Set a touch event for iv
iv.setOnTouchListener(new OnTouchListener() {

int startX = 0;
int startY = 0;
@Override
public boolean onTouch(View v, MotionEvent event) {
//[5] Get the event type of finger touch
int action = event.getAction();
//[6] Decide exactly what type of event it is
switch (action) {
case MotionEvent.ACTION_DOWN: //Press
//[7] Get finger press coordinates
startX = (int) event.getX();
startY= (int) event.getY();
System.out.println("Press:"+startX+"---"+startY);
break;

case MotionEvent.ACTION_MOVE://move
//[8] Get stop coordinates
int stopX = (int) event.getX();
int stopY = (int) event.getY();

System.out.println("move:"+stopX+"---"+stopY);

//[9] Draw lines
canvas.drawLine(startX, startY, stopX, stopY, paint);

//[9.1] Update the starting coordinates
startX = stopX;
startY = stopY;

//[10] Remember to update ui
iv.setImageBitmap(copyBitmap);

break;

case MotionEvent.ACTION_UP: //Lift up;
break;
}
return true;
}
});

}
```

6 tear clothes small case
```//[5] Set a touch event for iv
iv.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
//[6] Get the type of touch event
int action = event.getAction();
switch (action) {

case MotionEvent.ACTION_MOVE: //move

for (int i = -7; i < 7; i++) {  //Change x

for (int j = -7; j <7; j++) {
//Tear a circle for a good user experience
if (Math.sqrt(i*i+j*j)<7) {
//Modify one pixel at a time
try {
alterbBitmap.setPixel((int)event.getX()+i, (int)event.getY()+j, Color.TRANSPARENT);
} catch (Exception e) {
}
}

}

}

//Always remember to update iv
iv.setImageBitmap(alterbBitmap);
break;
}

return true;
}
});

```

7 Use mediaplayer to play audio files
[1] Role: This class is used to play audio or video

8Baidu Music Box Completed
[1] Get current song progress and total duration

[2] How to add a playback progress to the service

[3] Transfer data to mainActivity via handler
[4]seekbar Processing Data

Life cycle of 9 mediaplayer

Introduction to 10 surfaceview
The [1]surfaceview control is a heavyweight control
Two threads are maintained internally
A Get data and display it
B is responsible for displaying and retrieving data
[3] He can update the ui directly on the child thread. Progress-related controls can update the ui directly on the child thread

```

```
```	super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//Find Control
final SurfaceView sfv = (SurfaceView) findViewById(R.id.sfv);

final SurfaceHolder surfaceHolder = sfv.getHolder();

//Add a callback
surfaceHolder.addCallback(new Callback() {
//Called when surfaceview is destroyed
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
System.out.println("surfaceDestroyed");
if (player!=null && player.isPlaying()) {

//Get the location of the current video play

currentPosition = player.getCurrentPosition();
player.stop();

}

}

//When surfaceview is initialized
@Override
public void surfaceCreated(SurfaceHolder holder) {
//[1] Initialize mediaplayer
player = new MediaPlayer();

//[2] Set whether the path of the resource to play can be local or network
try {
player.setDataSource("http://192.168.13.89:8080/cc.MP4");

//[2.1] Setting the content to play video SurfaceHolder is the content used to maintain video playback
player.setDisplay(surfaceHolder);

//[3] Ready to Play
//						player.prepare();
player.prepareAsync();
//Set up a ready to finish listening
player.setOnPreparedListener(new OnPreparedListener() {

@Override
public void onPrepared(MediaPlayer mp) {
//[4] Start playing
player.start();
//[5] Continue playback from last position
player.seekTo(currentPosition);

}
});

} catch (Exception e) {
e.printStackTrace();
}
}

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

}
});

```

Supplement 1 VideoView
[1] This control encapsulates surfaceview and meidiaplayer
[2]meidiaplayer plays video. He only supports 3gp MP4 format

Supplement 2 vitamio framework
meidiaplayer
videoview
ffmpeg was written by dozens of C gods
Do not repeat wheel building Google
Multithreaded Breakpoint Download
xutils 360 Mobile Assistant Tencent Assistant

11 Photos and videos
Samsung Milliwa...
Shenzhen Huaqiangbei
The code is as follows

Posted on Thu, 04 Jul 2019 12:44:13 -0400 by flexxall