├── .gitignore
├── .project
├── CameraSample
├── app
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── hejunlin
│ │ │ └── camerasample
│ │ │ └── ApplicationTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── hejunlin
│ │ │ │ └── camerasample
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── SurfacePreview.java
│ │ └── res
│ │ │ ├── layout
│ │ │ └── activity_main.xml
│ │ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── capture.png
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── hejunlin
│ │ └── camerasample
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── CameraSample2
├── app
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── hejunlin
│ │ │ └── camerasample2
│ │ │ └── ApplicationTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── hejunlin
│ │ │ │ └── camerasample2
│ │ │ │ ├── Camera2Fragment.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── SuperTextureView.java
│ │ └── res
│ │ │ ├── layout
│ │ │ ├── activity_main.xml
│ │ │ └── fragment_camera2.xml
│ │ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── capture.png
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── hejunlin
│ │ └── camerasample2
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── GuardProcessSample
├── app
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── hejunlin
│ │ │ └── guardprocesssample
│ │ │ └── ApplicationTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── aidl
│ │ │ └── com
│ │ │ │ └── hejunlin
│ │ │ │ └── guardprocesssample
│ │ │ │ └── aidl
│ │ │ │ └── IBridgeInterface.aidl
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── hejunlin
│ │ │ │ └── guardprocesssample
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── ServiceA.java
│ │ │ │ └── ServiceB.java
│ │ └── res
│ │ │ ├── layout
│ │ │ └── activity_main.xml
│ │ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── hejunlin
│ │ └── guardprocesssample
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── LICENSE
├── MediaCodcSample
├── .gitignore
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── hejunlin
│ │ │ └── mediacodcsample
│ │ │ └── ApplicationTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── hejunlin
│ │ │ │ └── mediacodcsample
│ │ │ │ └── MainActivity.java
│ │ └── res
│ │ │ ├── layout
│ │ │ └── activity_main.xml
│ │ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── hejunlin
│ │ └── mediacodcsample
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── MediaPlayerSample
├── app
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── hejunlin
│ │ │ └── mediaplayersample
│ │ │ └── ApplicationTest.java
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── hejunlin
│ │ │ └── mediaplayersample
│ │ │ └── MainActivity.java
│ │ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── menu
│ │ └── menu_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── README.md
├── VideoWaterMarkSample
├── .gitignore
├── .idea
│ ├── compiler.xml
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── encodings.xml
│ ├── gradle.xml
│ ├── libraries
│ │ ├── animated_vector_drawable_23_3_0.xml
│ │ ├── appcompat_v7_23_3_0.xml
│ │ ├── hamcrest_core_1_3.xml
│ │ ├── junit_4_12.xml
│ │ ├── support_annotations_23_3_0.xml
│ │ ├── support_v4_23_3_0.xml
│ │ └── support_vector_drawable_23_3_0.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ └── workspace.xml
├── VideoWaterMarkSample.iml
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── hejunlin
│ │ │ └── videorecord
│ │ │ ├── ColorFormatUtil.java
│ │ │ ├── MainActivity.java
│ │ │ ├── TakeVideoActivity.java
│ │ │ ├── VideoCodecModel.java
│ │ │ └── VideoCodecTask.java
│ │ └── res
│ │ ├── drawable
│ │ ├── diverde.xml
│ │ ├── litte_red_point.xml
│ │ ├── play.xml
│ │ ├── play1.png
│ │ ├── play2.png
│ │ └── progressbar_drawable.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── activity_take_video.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ ├── capture.png
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── local.properties
└── settings.gradle
└── images
├── camera3.gif
├── camera5.gif
├── guard3.gif
├── mediacodec.gif
└── mediaplayer.png
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 |
39 | # Keystore files
40 | *.jks
41 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | MultiMediaSample
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/CameraSample/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.hejunlin.camerasample"
9 | minSdkVersion 17
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.4.0'
26 | }
27 |
--------------------------------------------------------------------------------
/CameraSample/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Studio SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/CameraSample/app/src/androidTest/java/com/hejunlin/camerasample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.camerasample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/CameraSample/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
16 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/CameraSample/app/src/main/java/com/hejunlin/camerasample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.camerasample;
2 |
3 | import android.hardware.Camera;
4 | import android.os.Environment;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.os.Bundle;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.widget.FrameLayout;
10 | import android.widget.ImageView;
11 | import android.widget.Toast;
12 |
13 | import java.io.File;
14 | import java.io.FileNotFoundException;
15 | import java.io.FileOutputStream;
16 | import java.io.IOException;
17 | import java.text.SimpleDateFormat;
18 | import java.util.Date;
19 | import java.util.jar.Manifest;
20 |
21 | public class MainActivity extends AppCompatActivity implements Camera.PictureCallback, View.OnClickListener {
22 |
23 | private static final String TAG = MainActivity.class.getSimpleName();
24 | private SurfacePreview mCameraSurPreview;
25 | private ImageView mCaptureButton;
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_main);
31 |
32 | // Create our Preview view and set it as the content of our activity.
33 | FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
34 | mCameraSurPreview = new SurfacePreview(this);
35 | preview.addView(mCameraSurPreview);
36 |
37 | // Add a listener to the Capture button
38 | mCaptureButton = (ImageView) findViewById(R.id.capture);
39 | mCaptureButton.setOnClickListener(this);
40 | }
41 |
42 | @Override
43 | public void onPictureTaken(byte[] data, Camera camera) {
44 | //save the picture to sdcard
45 | File pictureFile = getOutputMediaFile();
46 | if (pictureFile == null){
47 | Log.d(TAG, "Error creating media file, check storage permissions: ");
48 | return;
49 | }
50 |
51 | try {
52 | FileOutputStream fos = new FileOutputStream(pictureFile);
53 | fos.write(data);
54 | fos.close();
55 | } catch (FileNotFoundException e) {
56 | Log.d(TAG, "File not found: " + e.getMessage());
57 | } catch (IOException e) {
58 | Log.d(TAG, "Error accessing file: " + e.getMessage());
59 | }
60 |
61 | // Restart the preview and re-enable the shutter button so that we can take another picture
62 | camera.startPreview();
63 |
64 | //See if need to enable or not
65 | mCaptureButton.setEnabled(true);
66 | Toast.makeText(this, "拍照成功", Toast.LENGTH_LONG).show();
67 | }
68 |
69 | @Override
70 | public void onClick(View v) {
71 | mCaptureButton.setEnabled(false);
72 | // get an image from the camera
73 | mCameraSurPreview.takePicture(this);
74 | }
75 |
76 | private File getOutputMediaFile(){
77 | //get the mobile Pictures directory
78 | File picDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
79 | //get the current time
80 | String timeStamp = new SimpleDateFormat("yyyy-MMdd-HHmmss").format(new Date());
81 | return new File(picDir.getPath() + File.separator + "hejunlin_"+ timeStamp + ".jpg");
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/CameraSample/app/src/main/java/com/hejunlin/camerasample/SurfacePreview.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.camerasample;
2 |
3 | import android.content.Context;
4 | import android.graphics.PixelFormat;
5 | import android.hardware.Camera;
6 | import android.os.Build;
7 | import android.util.Log;
8 | import android.view.SurfaceHolder;
9 | import android.view.SurfaceView;
10 |
11 | import java.io.IOException;
12 | import java.lang.reflect.Method;
13 |
14 | /**
15 | * Created by hejunlin on 2016/10/5.
16 | */
17 | public class SurfacePreview extends SurfaceView implements SurfaceHolder.Callback {
18 |
19 | private static final String TAG = SurfacePreview.class.getSimpleName();
20 | private SurfaceHolder mHolder;
21 | private Camera mCamera;
22 | private Camera.Parameters mParameters;
23 |
24 | public SurfacePreview(Context context) {
25 | super(context);
26 |
27 | // Install a SurfaceHolder.Callback so we get notified when the
28 | // underlying surface is created and destroyed.
29 | mHolder = getHolder();
30 | mHolder.setFormat(PixelFormat.TRANSPARENT);
31 | mHolder.addCallback(this);
32 | // deprecated setting, but required on Android versions prior to 3.0
33 | mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
34 | }
35 |
36 | public void surfaceCreated(SurfaceHolder holder) {
37 | Log.d(TAG, "surfaceCreated() is called");
38 | try {
39 | // Open the Camera in preview mode
40 | mCamera = Camera.open(0);
41 | mCamera.setDisplayOrientation(90);
42 | mCamera.setPreviewDisplay(holder);
43 | mCamera.startPreview();
44 | } catch (IOException e) {
45 | Log.d(TAG, "Error setting camera preview: " + e.getMessage());
46 | }
47 | }
48 |
49 | public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
50 | Log.d(TAG, "surfaceChanged() is called");
51 | try {
52 | // mCamera.startPreview();
53 | mCamera.autoFocus(new Camera.AutoFocusCallback() {
54 | @Override
55 | public void onAutoFocus(boolean success, Camera camera) {
56 | if(success){
57 | initCamera();
58 | camera.cancelAutoFocus();
59 | }
60 | }
61 | });
62 | } catch (Exception e){
63 | Log.d(TAG, "Error starting camera preview: " + e.getMessage());
64 | }
65 | }
66 |
67 | private void initCamera() {
68 | mParameters = mCamera.getParameters();
69 | mParameters.setPictureFormat(PixelFormat.JPEG);
70 | mParameters.setPictureSize(1080,1920);
71 | mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
72 | mParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
73 | setDispaly(mParameters, mCamera);
74 | mCamera.setParameters(mParameters);
75 | mCamera.startPreview();
76 | mCamera.cancelAutoFocus();
77 |
78 | }
79 | private void setDispaly(Camera.Parameters parameters,Camera camera) {
80 | if (Integer.parseInt(Build.VERSION.SDK) >= 8){
81 | setDisplayOrientation(camera,90);
82 | } else {
83 | parameters.setRotation(90);
84 | }
85 | }
86 |
87 | private void setDisplayOrientation(Camera camera, int i) {
88 | Method downPolymorphic;
89 | try{
90 | downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[]{int.class});
91 | if(downPolymorphic!=null) {
92 | downPolymorphic.invoke(camera, new Object[]{i});
93 | }
94 | }
95 | catch(Exception e){
96 | Log.e(TAG, "image error");
97 | }
98 | }
99 |
100 | public void surfaceDestroyed(SurfaceHolder holder) {
101 | if (mCamera != null) {
102 | mCamera.stopPreview();
103 | mCamera.release();
104 | mCamera = null;
105 | }
106 | Log.d(TAG, "surfaceDestroyed() is called");
107 | }
108 |
109 | public void takePicture(Camera.PictureCallback imageCallback) {
110 | mCamera.takePicture(null, null, imageCallback);
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/CameraSample/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
17 |
18 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/CameraSample/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CameraSample/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CameraSample/app/src/main/res/mipmap-xhdpi/capture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample/app/src/main/res/mipmap-xhdpi/capture.png
--------------------------------------------------------------------------------
/CameraSample/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CameraSample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CameraSample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CameraSample/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/CameraSample/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/CameraSample/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/CameraSample/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CameraSample
3 |
4 |
--------------------------------------------------------------------------------
/CameraSample/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/CameraSample/app/src/test/java/com/hejunlin/camerasample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.camerasample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/CameraSample/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/CameraSample/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/CameraSample/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/CameraSample/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/CameraSample/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/CameraSample/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/CameraSample/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/CameraSample2/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.hejunlin.camerasample2"
9 | minSdkVersion 17
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.4.0'
26 | compile "com.android.support:support-v13:23.4.0"
27 | compile "com.android.support:support-v4:23.4.0"
28 | compile "com.android.support:cardview-v7:23.4.0"
29 | }
30 |
--------------------------------------------------------------------------------
/CameraSample2/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Studio SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/CameraSample2/app/src/androidTest/java/com/hejunlin/camerasample2/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.camerasample2;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/java/com/hejunlin/camerasample2/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.camerasample2;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | public class MainActivity extends AppCompatActivity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.activity_main);
12 | if (null == savedInstanceState) {
13 | getFragmentManager().beginTransaction()
14 | .replace(R.id.container, Camera2Fragment.newInstance())
15 | .commit();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/java/com/hejunlin/camerasample2/SuperTextureView.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.camerasample2;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.TextureView;
6 |
7 | /**
8 | * A {@link TextureView} that can be adjusted to a specified aspect ratio.
9 | */
10 | public class SuperTextureView extends TextureView {
11 |
12 | private int mRatioWidth = 0;
13 | private int mRatioHeight = 0;
14 |
15 | public SuperTextureView(Context context) {
16 | this(context, null);
17 | }
18 |
19 | public SuperTextureView(Context context, AttributeSet attrs) {
20 | this(context, attrs, 0);
21 | }
22 |
23 | public SuperTextureView(Context context, AttributeSet attrs, int defStyle) {
24 | super(context, attrs, defStyle);
25 | }
26 |
27 | /**
28 | * Sets the aspect ratio for this view. The size of the view will be measured based on the ratio
29 | * calculated from the parameters. Note that the actual sizes of parameters don't matter, that
30 | * is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result.
31 | *
32 | * @param width Relative horizontal size
33 | * @param height Relative vertical size
34 | */
35 | // public void setAspectRatio(int width, int height) {
36 | // if (width < 0 || height < 0) {
37 | // throw new IllegalArgumentException("Size cannot be negative.");
38 | // }
39 | // mRatioWidth = width;
40 | // mRatioHeight = height;
41 | // requestLayout();
42 | // }
43 | //
44 | // @Override
45 | // protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
46 | // super.onMeasure(widthMeasureSpec, heightMeasureSpec);
47 | // int width = MeasureSpec.getSize(widthMeasureSpec);
48 | // int height = MeasureSpec.getSize(heightMeasureSpec);
49 | // if (0 == mRatioWidth || 0 == mRatioHeight) {
50 | // setMeasuredDimension(width, height);
51 | // } else {
52 | // if (width < height * mRatioWidth / mRatioHeight) {
53 | // setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
54 | // } else {
55 | // setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
56 | // }
57 | // }
58 | // }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/res/layout/fragment_camera2.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
18 |
19 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample2/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample2/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/res/mipmap-xhdpi/capture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample2/app/src/main/res/mipmap-xhdpi/capture.png
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample2/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample2/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample2/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CameraSample2
3 |
4 |
--------------------------------------------------------------------------------
/CameraSample2/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/CameraSample2/app/src/test/java/com/hejunlin/camerasample2/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.camerasample2;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/CameraSample2/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/CameraSample2/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/CameraSample2/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/CameraSample2/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/CameraSample2/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/CameraSample2/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/CameraSample2/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/CameraSample2/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.hejunlin.guardprocesssample"
9 | minSdkVersion 17
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.4.0'
26 | }
27 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Studio SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/androidTest/java/com/hejunlin/guardprocesssample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.guardprocesssample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/aidl/com/hejunlin/guardprocesssample/aidl/IBridgeInterface.aidl:
--------------------------------------------------------------------------------
1 | // IBridgeInterface.aidl
2 | package com.hejunlin.guardprocesssample.aidl;
3 |
4 | // Declare any non-default types here with import statements
5 |
6 | interface IBridgeInterface {
7 | /**
8 | * Demonstrates some basic types that you can use as parameters
9 | * and return values in AIDL.
10 | */
11 | // void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
12 | // double aDouble, String aString);
13 | String getName();
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/java/com/hejunlin/guardprocesssample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.guardprocesssample;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 |
7 | public class MainActivity extends AppCompatActivity {
8 |
9 | @Override
10 | protected void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_main);
13 | // 启动两个守护服务
14 | startService(new Intent(this, ServiceA.class));
15 | startService(new Intent(this, ServiceB.class));
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/java/com/hejunlin/guardprocesssample/ServiceA.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.guardprocesssample;
2 |
3 | import android.app.Notification;
4 | import android.app.PendingIntent;
5 | import android.app.Service;
6 | import android.content.ComponentName;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.content.ServiceConnection;
10 | import android.os.IBinder;
11 | import android.os.RemoteException;
12 | import android.util.Log;
13 | import android.widget.Toast;
14 |
15 | import com.hejunlin.guardprocesssample.aidl.IBridgeInterface;
16 |
17 | /**
18 | * Created by hejunlin on 2016/10/10.
19 | */
20 | public class ServiceA extends Service {
21 |
22 | private static final String TAG = ServiceA.class.getSimpleName();
23 | private MyBinder mBinder;
24 | private PendingIntent mPendingIntent;
25 | private MyServiceConnection mServiceConnection;
26 |
27 | @Override
28 | public void onCreate() {
29 | super.onCreate();
30 | if (mBinder == null) {
31 | mBinder = new MyBinder();
32 | }
33 | mServiceConnection = new MyServiceConnection();
34 | }
35 |
36 | @Override
37 | public int onStartCommand(Intent intent, int flags, int startId) {
38 | this.bindService(new Intent(this, ServiceB.class), mServiceConnection, Context.BIND_IMPORTANT);
39 | mPendingIntent = PendingIntent.getService(this, 0, intent, 0);
40 | Notification.Builder builder = new Notification.Builder(this);
41 | builder.setTicker("守护服务A启动中")
42 | .setContentText("我是来守护B不被杀的!")
43 | .setContentTitle("守护服务A")
44 | .setSmallIcon(R.mipmap.ic_launcher)
45 | .setContentIntent(mPendingIntent)
46 | .setWhen(System.currentTimeMillis());
47 | Notification notification = builder.build();
48 | // 设置service为前台进程,避免手机休眠时系统自动杀掉该服务
49 | startForeground(startId, notification);
50 | return START_STICKY;
51 | }
52 |
53 | class MyServiceConnection implements ServiceConnection {
54 |
55 | @Override
56 | public void onServiceConnected(ComponentName componentName, IBinder binder) {
57 | Log.i(TAG, "ServiceA连接成功");
58 | Toast.makeText(ServiceA.this, "ServiceA连接成功", Toast.LENGTH_LONG).show();
59 | }
60 |
61 | @Override
62 | public void onServiceDisconnected(ComponentName componentName) {
63 | // 连接出现了异常断开了,RemoteService被杀掉了
64 | Toast.makeText(ServiceA.this, "ServiceA被干掉", Toast.LENGTH_LONG).show();
65 | // 启动ServiceB
66 | ServiceA.this.startService(new Intent(ServiceA.this, ServiceB.class));
67 | ServiceA.this.bindService(new Intent(ServiceA.this, ServiceB.class),
68 | mServiceConnection, Context.BIND_IMPORTANT);
69 | }
70 |
71 | }
72 |
73 | class MyBinder extends IBridgeInterface.Stub {
74 |
75 | @Override
76 | public String getName() throws RemoteException {
77 | return "ServiceA";
78 | }
79 |
80 | }
81 |
82 | @Override
83 | public IBinder onBind(Intent intent) {
84 | return mBinder;
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/java/com/hejunlin/guardprocesssample/ServiceB.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.guardprocesssample;
2 |
3 | import android.app.Notification;
4 | import android.app.PendingIntent;
5 | import android.app.Service;
6 | import android.content.ComponentName;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.content.ServiceConnection;
10 | import android.os.IBinder;
11 | import android.os.RemoteException;
12 | import android.util.Log;
13 | import android.widget.Toast;
14 |
15 | import com.hejunlin.guardprocesssample.aidl.IBridgeInterface;
16 |
17 | /**
18 | * Created by hejunlin on 2016/10/10.
19 | */
20 | public class ServiceB extends Service {
21 |
22 | private static final String TAG = ServiceB.class.getSimpleName();
23 | private MyBinder mBinder;
24 | private PendingIntent mPendingIntent;
25 | private MyServiceConnection mServiceConnection;
26 |
27 | @Override
28 | public void onCreate() {
29 | super.onCreate();
30 | if (mBinder == null) {
31 | mBinder = new MyBinder();
32 | }
33 | mServiceConnection = new MyServiceConnection();
34 | }
35 |
36 | @Override
37 | public int onStartCommand(Intent intent, int flags, int startId) {
38 | this.bindService(new Intent(this,ServiceA.class), mServiceConnection, Context.BIND_IMPORTANT);
39 | mPendingIntent =PendingIntent.getService(this, 0, intent, 0);
40 | Notification.Builder builder = new Notification.Builder(this);
41 | builder.setTicker("守护服务B启动中")
42 | .setContentText("我是来守护A不被杀的!")
43 | .setContentTitle("守护服务B")
44 | .setSmallIcon(R.mipmap.ic_launcher)
45 | .setContentIntent(mPendingIntent)
46 | .setWhen(System.currentTimeMillis());
47 | Notification notification = builder.build();
48 | //设置service为前台进程,避免手机休眠时系统自动杀掉该服务
49 | startForeground(startId, notification);
50 | return START_STICKY;
51 | }
52 |
53 | class MyServiceConnection implements ServiceConnection {
54 |
55 | @Override
56 | public void onServiceConnected(ComponentName componentName, IBinder binder) {
57 | Log.i(TAG, "ServiceB连接成功");
58 | Toast.makeText(ServiceB.this, "ServiceB连接成功", Toast.LENGTH_LONG).show();
59 | }
60 |
61 | @Override
62 | public void onServiceDisconnected(ComponentName componentName) {
63 | // 连接出现了异常断开了,LocalCastielService被杀死了
64 | Toast.makeText(ServiceB.this, "ServiceB被干掉", Toast.LENGTH_LONG).show();
65 | // 启动ServiceA
66 | ServiceB.this.startService(new Intent(ServiceB.this, ServiceA.class));
67 | ServiceB.this.bindService(new Intent(ServiceB.this, ServiceA.class), mServiceConnection, Context.BIND_IMPORTANT);
68 | }
69 |
70 | }
71 |
72 | class MyBinder extends IBridgeInterface.Stub {
73 |
74 | @Override
75 | public String getName() throws RemoteException {
76 | return "ServiceB";
77 | }
78 |
79 | }
80 |
81 | @Override
82 | public IBinder onBind(Intent intent) {
83 | return mBinder;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/GuardProcessSample/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/GuardProcessSample/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/GuardProcessSample/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/GuardProcessSample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/GuardProcessSample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GuardProcessSample
3 |
4 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/GuardProcessSample/app/src/test/java/com/hejunlin/guardprocesssample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.guardprocesssample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/GuardProcessSample/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/GuardProcessSample/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/GuardProcessSample/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/GuardProcessSample/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/GuardProcessSample/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/GuardProcessSample/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/GuardProcessSample/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/GuardProcessSample/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/MediaCodcSample/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/MediaCodcSample/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/MediaCodcSample/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.hejunlin.mediacodcsample"
9 | minSdkVersion 17
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.4.0'
26 | }
27 |
--------------------------------------------------------------------------------
/MediaCodcSample/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Studio SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/androidTest/java/com/hejunlin/mediacodcsample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.mediacodcsample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/main/java/com/hejunlin/mediacodcsample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.mediacodcsample;
2 |
3 | import android.media.MediaCodec;
4 | import android.media.MediaExtractor;
5 | import android.media.MediaFormat;
6 | import android.os.Environment;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.os.Bundle;
9 | import android.util.Log;
10 | import android.view.Surface;
11 | import android.view.SurfaceHolder;
12 | import android.view.SurfaceView;
13 |
14 | import java.io.IOException;
15 | import java.nio.ByteBuffer;
16 |
17 | public class MainActivity extends AppCompatActivity implements SurfaceHolder.Callback {
18 |
19 | private static final String SAMPLE = Environment.getExternalStorageDirectory() + "/device-2016-11-15.mp4";
20 | private static final String TAG = MainActivity.class.getSimpleName();
21 | private WorkThread mWorkThread = null;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | SurfaceView surfaceView = new SurfaceView(this);
27 | /*下面设置Surface不维护自己的缓冲区,而是等待屏幕的渲染引擎将内容推送到用户面前*/
28 | surfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
29 | surfaceView.getHolder().addCallback(this);
30 | setContentView(surfaceView);
31 | }
32 |
33 | protected void onDestroy() {
34 | super.onDestroy();
35 | }
36 |
37 | @Override
38 | public void surfaceCreated(SurfaceHolder holder) {
39 | }
40 |
41 | @Override
42 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
43 | if (mWorkThread == null) {
44 | mWorkThread = new WorkThread(holder.getSurface());
45 | mWorkThread.start();
46 | }
47 | }
48 |
49 | @Override
50 | public void surfaceDestroyed(SurfaceHolder holder) {
51 | if (mWorkThread != null) {
52 | mWorkThread.interrupt();
53 | }
54 | }
55 |
56 | private class WorkThread extends Thread {
57 | private MediaExtractor mMediaExtractor;
58 | private MediaCodec mMediaCodec;
59 | private Surface mSurface;
60 |
61 | public WorkThread(Surface surface) {
62 | this.mSurface = surface;
63 | }
64 |
65 | @Override
66 | public void run() {
67 | mMediaExtractor = new MediaExtractor();//数据解析器
68 | try {
69 | mMediaExtractor.setDataSource(SAMPLE);
70 | } catch (IOException e) {
71 | e.printStackTrace();
72 | }
73 |
74 | for (int i = 0; i < mMediaExtractor.getTrackCount(); i++) {//遍历数据源音视频轨迹
75 | MediaFormat format = mMediaExtractor.getTrackFormat(i);
76 | Log.d(TAG, ">> format i " + i + ": " + format);
77 | String mime = format.getString(MediaFormat.KEY_MIME);
78 | Log.d(TAG, ">> mime i " + i + ": " + mime);
79 | if (mime.startsWith("video/")) {
80 | mMediaExtractor.selectTrack(i);
81 | try {
82 | mMediaCodec = MediaCodec.createDecoderByType(mime);
83 | } catch (IOException e) {
84 | e.printStackTrace();
85 | }
86 | mMediaCodec.configure(format, mSurface, null, 0);
87 | break;
88 | }
89 | }
90 | if (mMediaCodec == null) {
91 | return;
92 | }
93 | mMediaCodec.start();//调用start后,如果没有异常信息,就表示成功构建组件
94 | ByteBuffer[] inputBuffers = mMediaCodec.getInputBuffers();
95 | ByteBuffer[] outputBuffers = mMediaCodec.getOutputBuffers();
96 | // 每个buffer的元数据包括具体范围偏移及大小 ,及有效数据中相关解码的buffer
97 | MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
98 | boolean isEOS = false;
99 | long startMs = System.currentTimeMillis();
100 |
101 | while (!Thread.interrupted()) {//只要线程不中断
102 | if (!isEOS) {
103 | //返回用有效输出的buffer的索引,如果没有相关buffer可用,就返回-1
104 | //如果传入的timeoutUs为0,将立马返回,如果输入buffer可用,将无限期等待
105 | //timeoutUs的单位是微秒
106 | int inIndex = mMediaCodec.dequeueInputBuffer(10000);//0.01s
107 | if (inIndex >= 0) {
108 | ByteBuffer buffer = inputBuffers[inIndex];
109 | Log.d(TAG, ">> buffer " + buffer);
110 | int sampleSize = mMediaExtractor.readSampleData(buffer, 0);
111 | Log.d(TAG, ">> sampleSize " + sampleSize);
112 | if (sampleSize < 0) {
113 | // We shouldn't stop the playback at this point, just pass the EOS
114 | // flag to mMediaCodec, we will get it again from the
115 | // dequeueOutputBuffer
116 | Log.d(TAG, "InputBuffer BUFFER_FLAG_END_OF_STREAM");
117 | mMediaCodec.queueInputBuffer(inIndex, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
118 | isEOS = true;
119 | } else {
120 | mMediaCodec.queueInputBuffer(inIndex, 0, sampleSize, mMediaExtractor.getSampleTime(), 0);
121 | mMediaExtractor.advance();
122 | }
123 | }
124 | }
125 |
126 | int outIndex = mMediaCodec.dequeueOutputBuffer(info, 10000);
127 | switch (outIndex) {
128 | case MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED://当buffer变化时,client必须重新指向新的buffer
129 | Log.d(TAG, ">> output buffer changed ");
130 | outputBuffers = mMediaCodec.getOutputBuffers();
131 | break;
132 | case MediaCodec.INFO_OUTPUT_FORMAT_CHANGED://当buffer的封装格式变化,须指向新的buffer格式
133 | Log.d(TAG, ">> output buffer changed ");
134 | break;
135 | case MediaCodec.INFO_TRY_AGAIN_LATER://当dequeueOutputBuffer超时,会到达此case
136 | Log.d(TAG, ">> dequeueOutputBuffer timeout ");
137 | break;
138 | default:
139 | ByteBuffer buffer = outputBuffers[outIndex];
140 | // We use a very simple clock to keep the video FPS, or the video
141 | // playback will be too fast
142 | while (info.presentationTimeUs / 1000 > System.currentTimeMillis() - startMs) {
143 | try {
144 | sleep(10);
145 | } catch (InterruptedException e) {
146 | e.printStackTrace();
147 | break;
148 | }
149 | }
150 | mMediaCodec.releaseOutputBuffer(outIndex, true);
151 | break;
152 | }
153 | // All decoded frames have been rendered, we can stop playing now
154 | if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
155 | Log.d(TAG, "OutputBuffer BUFFER_FLAG_END_OF_STREAM");
156 | break;
157 | }
158 | }
159 | mMediaCodec.stop();
160 | mMediaCodec.release();//释放组件
161 | mMediaExtractor.release();
162 | }
163 | }
164 |
165 | }
166 |
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/MediaCodcSample/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/MediaCodcSample/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/MediaCodcSample/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/MediaCodcSample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/MediaCodcSample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MediaCodcSample
3 |
4 |
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/MediaCodcSample/app/src/test/java/com/hejunlin/mediacodcsample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.mediacodcsample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/MediaCodcSample/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/MediaCodcSample/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/MediaCodcSample/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/MediaCodcSample/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/MediaCodcSample/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/MediaCodcSample/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/MediaCodcSample/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/MediaCodcSample/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/MediaPlayerSample/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.hejunlin.mediaplayersample"
9 | minSdkVersion 21
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | }
26 |
--------------------------------------------------------------------------------
/MediaPlayerSample/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/hejunlin/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/androidTest/java/com/hejunlin/mediaplayersample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.mediaplayersample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/main/java/com/hejunlin/mediaplayersample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.mediaplayersample;
2 |
3 |
4 | import android.media.AudioManager;
5 | import android.media.MediaPlayer;
6 | import android.media.MediaPlayer.OnCompletionListener;
7 | import android.os.Bundle;
8 | import android.os.SystemClock;
9 | import android.view.Surface;
10 | import android.view.SurfaceHolder;
11 | import android.view.SurfaceView;
12 | import android.view.View;
13 | import android.widget.EditText;
14 | import android.widget.SeekBar;
15 | import android.widget.Toast;
16 | import android.widget.SeekBar.OnSeekBarChangeListener;
17 | import android.widget.TextView;
18 | import android.app.Activity;
19 |
20 |
21 | public class MainActivity extends Activity implements OnSeekBarChangeListener, OnCompletionListener {
22 |
23 | private boolean isStopUpdatingProgress=false;
24 | private EditText etPath;
25 | private MediaPlayer mMediapPlayer;
26 | private SeekBar mSeekbar;
27 | private TextView tvCurrentTime;
28 | private TextView tvTotalTime;
29 |
30 | private final int NORMAL=0;//闲置
31 | private final int PLAYING=1;//播放中
32 | private final int PAUSING=2;//暂停
33 | private final int STOPING=3;//停止中
34 |
35 | private int currentstate=NORMAL;//播放器当前的状态,默认是空闲状态
36 |
37 | //用行动打消忧虑
38 | private SurfaceHolder holder;
39 |
40 | @Override
41 | protected void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 | setContentView(R.layout.activity_main);
44 |
45 | etPath=(EditText)findViewById(R.id.et_path);
46 | mSeekbar=(SeekBar) findViewById(R.id.sb_progress);
47 | tvCurrentTime=(TextView)findViewById(R.id.tv_current_time);
48 | tvTotalTime=(TextView)findViewById(R.id.tv_total_time);
49 |
50 | mSeekbar.setOnSeekBarChangeListener(this);
51 |
52 | SurfaceView mSurfaceView=(SurfaceView) findViewById(R.id.surfaceview);
53 | holder=mSurfaceView.getHolder();//SurfaceView帮助类对象
54 |
55 | //是采用自己内部的双缓冲区,而是等待别人推送数据
56 |
57 | holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
58 |
59 | }
60 |
61 | /**
62 | * 开始
63 | * @param v
64 | */
65 | public void start(View v){
66 | if(mMediapPlayer!=null){
67 | if(currentstate!=PAUSING){
68 | mMediapPlayer.start();
69 | currentstate=PLAYING;
70 | isStopUpdatingProgress=false;//每次在调用刷新线程时,都要设为false
71 | return ;
72 | //下面这个判断完美的解决了停止后重新播放的,释放两个资源的问题
73 | }else if(currentstate==STOPING){
74 | mMediapPlayer.reset();
75 | mMediapPlayer.release();
76 | }
77 | }
78 | play();
79 |
80 | }
81 | /**
82 | * 停止
83 | * @param v
84 | */
85 | public void stop(View v){
86 | if(mMediapPlayer!=null){
87 | mMediapPlayer.stop();
88 | }
89 | }
90 |
91 | /**
92 | * 播放输入框的文件
93 | */
94 | private void play(){
95 | String path=etPath.getText().toString().trim();
96 | mMediapPlayer=new MediaPlayer();
97 | try {
98 | //设置数据类型
99 | mMediapPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
100 | //设置以下播放器显示的位置
101 | mMediapPlayer.setDisplay(holder);
102 |
103 | mMediapPlayer.setDataSource(path);
104 | mMediapPlayer.prepare();
105 | mMediapPlayer.start();
106 |
107 | mMediapPlayer .setOnCompletionListener(this);
108 | //把当前播放器的状诚置为:播放中
109 | currentstate=PLAYING;
110 |
111 | //把音乐文件的总长度取出来,设置给seekbar作为最大值
112 | int duration=mMediapPlayer.getDuration();//总时长
113 | mSeekbar.setMax(duration);
114 | //把总时间显示textView上
115 | int m=duration/1000/60;
116 | int s=duration/1000%60;
117 | tvTotalTime.setText("/"+m+":"+s);
118 | tvCurrentTime.setText("00:00");
119 |
120 | isStopUpdatingProgress=false;
121 | new Thread(new UpdateProgressRunnable()).start();
122 |
123 |
124 | }catch(Exception e) {
125 | e.printStackTrace();
126 | }
127 | }
128 |
129 | /**
130 | * 暂停
131 | * @param v
132 | */
133 | public void pause(View v){
134 | if(mMediapPlayer!=null&¤tstate==PLAYING){
135 |
136 | mMediapPlayer.pause();
137 | currentstate=PAUSING;
138 | isStopUpdatingProgress=true;//停止刷新主线程
139 | }
140 | }
141 |
142 | /**
143 | * 重播
144 | * @param v
145 | */
146 | public void restart(View v){
147 | if(mMediapPlayer!=null){
148 | mMediapPlayer.reset();
149 | mMediapPlayer.release();
150 | play();
151 | }
152 | }
153 |
154 | @Override
155 | public void onProgressChanged(SeekBar seekBar, int progress,
156 | boolean fromUser) {
157 |
158 | }
159 |
160 | @Override
161 | public void onStartTrackingTouch(SeekBar seekBar) {
162 | isStopUpdatingProgress=true;//当开始拖动时,那么就开始停止刷新线程
163 | }
164 |
165 |
166 | @Override
167 | public void onStopTrackingTouch(SeekBar seekBar) {
168 | int progress=seekBar.getProgress();
169 | //播放器切换到指定的进度位置上
170 | mMediapPlayer.seekTo(progress);
171 | isStopUpdatingProgress=false;
172 | new Thread(new UpdateProgressRunnable()).start();
173 | }
174 |
175 | /**
176 | * 当播放完成时回调此方法
177 | */
178 | @Override
179 | public void onCompletion(MediaPlayer mp) {
180 | Toast.makeText(this, "播放完了,重新再播放", 0).show();
181 | mp.start();
182 |
183 | }
184 |
185 | /**
186 | * 刷新进度和时间的任务
187 | * @author hjl
188 | *
189 | */
190 | class UpdateProgressRunnable implements Runnable{
191 |
192 | @Override
193 | public void run() {
194 | //每隔1秒钟取一下当前正在播放的进度,设置给seekbar
195 | while(!isStopUpdatingProgress){
196 | //得到当前进度
197 | int currentPosition=mMediapPlayer.getCurrentPosition();
198 | mSeekbar.setProgress(currentPosition);
199 | final int m=currentPosition/1000/60;
200 | final int s=currentPosition/1000%60;
201 |
202 | //此方法给定的runable对象,会执行主线程(UI线程中)
203 | runOnUiThread(new Runnable(){
204 |
205 | @Override
206 | public void run() {
207 | tvCurrentTime.setText(m+":"+s);
208 |
209 | }
210 |
211 | });
212 | SystemClock.sleep(1000);
213 | }
214 |
215 | }
216 |
217 | }
218 |
219 | }
220 |
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
14 |
15 |
19 |
20 |
25 |
26 |
31 |
32 |
37 |
38 |
43 |
44 |
45 |
49 |
50 |
54 |
55 |
61 |
62 |
68 |
69 |
70 |
74 |
75 |
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/MediaPlayerSample/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/MediaPlayerSample/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/MediaPlayerSample/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/MediaPlayerSample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MediaPlayerSample
3 |
4 | Hello world!
5 | Settings
6 |
7 |
--------------------------------------------------------------------------------
/MediaPlayerSample/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/MediaPlayerSample/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.3.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/MediaPlayerSample/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/MediaPlayerSample/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/MediaPlayerSample/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/MediaPlayerSample/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Aug 30 23:43:56 CST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
7 |
--------------------------------------------------------------------------------
/MediaPlayerSample/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/MediaPlayerSample/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/MediaPlayerSample/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/README.md
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/libraries/animated_vector_drawable_23_3_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/libraries/appcompat_v7_23_3_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/libraries/hamcrest_core_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/libraries/junit_4_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/libraries/support_annotations_23_3_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/libraries/support_v4_23_3_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/libraries/support_vector_drawable_23_3_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Class structureJava
12 |
13 |
14 | Code maturity issuesJava
15 |
16 |
17 | Java
18 |
19 |
20 | Java language level migration aidsJava
21 |
22 |
23 | Javadoc issuesJava
24 |
25 |
26 | Performance issuesJava
27 |
28 |
29 | TestNGJava
30 |
31 |
32 | Threading issuesJava
33 |
34 |
35 |
36 |
37 | Android
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/VideoWaterMarkSample.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.hejunlin.videorecord"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | // proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.3.0'
25 | }
26 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/java/com/hejunlin/videorecord/ColorFormatUtil.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.videorecord;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.graphics.ImageFormat;
6 | import android.graphics.Rect;
7 | import android.graphics.YuvImage;
8 |
9 | import java.io.ByteArrayOutputStream;
10 |
11 |
12 | public class ColorFormatUtil {
13 |
14 | //RGB转YUV420sp
15 | public static byte[] convertRGB2YUV420sp(int[] argb, int width, int height) {
16 | final int frameSize = width * height;
17 |
18 | byte[] yuv420sp = new byte[frameSize * 3 / 2];
19 |
20 | int yIndex = 0;
21 | int uvIndex = frameSize;
22 |
23 | int R, G, B, Y, U, V;
24 | int index = 0;
25 | for (int j = 0; j < height; j++) {
26 | for (int i = 0; i < width; i++) {
27 |
28 | R = (argb[index] & 0xff0000) >> 16;
29 | G = (argb[index] & 0xff00) >> 8;
30 | B = (argb[index] & 0xff) >> 0;
31 |
32 | // well known RGB to YUV algorithm
33 | Y = ((66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
34 | U = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
35 | V = ((112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
36 |
37 | // NV21 has a plane of Y and interleaved planes of VU each sampled by a factor of 2
38 | // meaning for every 4 Y pixels there are 1 V and 1 U. Note the sampling is every other
39 | // pixel AND every other scanline.
40 | yuv420sp[yIndex++] = (byte) ((Y < 0) ? 0 : ((Y > 255) ? 255 : Y));
41 | if (j % 2 == 0 && index % 2 == 0) {
42 | yuv420sp[uvIndex++] = (byte) ((V < 0) ? 0 : ((V > 255) ? 255 : V));
43 | yuv420sp[uvIndex++] = (byte) ((U < 0) ? 0 : ((U > 255) ? 255 : U));
44 | }
45 |
46 | index++;
47 | }
48 | }
49 | return yuv420sp;
50 | }
51 |
52 | //RGB转YUV420p
53 | public static byte[] convertRGB2YUV420p(int[] argb, int width, int height) {
54 | int size = width * height * 3 / 2;
55 | byte[] yuv420p = new byte[size];
56 | int frameSize = width * height;
57 | int uIndex = frameSize;
58 | int vIndex = frameSize * 5 / 4;
59 |
60 | int R, G, B, Y, U, V;
61 | int index = 0;
62 | for (int j = 0; j < height; j++) {
63 | for (int i = 0; i < width; i++) {
64 | R = (argb[index] & 0xff0000) >> 16;
65 | G = (argb[index] & 0xff00) >> 8;
66 | B = (argb[index] & 0xff) >> 0;
67 |
68 | // well known RGB to YUV algorithm
69 | Y = ((66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
70 | U = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
71 | V = ((112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
72 |
73 | // NV21 has a plane of Y and interleaved planes of VU each sampled by a factor of 2
74 | // meaning for every 4 Y pixels there are 1 V and 1 U. Note the sampling is every other
75 | // pixel AND every other scanline.
76 | yuv420p[index++] = (byte) (Y < 0 ? 0 : (Y > 255 ? 255 : Y));
77 | if (j % 2 == 0 && index % 2 == 0) {
78 | yuv420p[uIndex++] = (byte) (U < 0 ? 0 : (U > 255 ? 255 : U));
79 | yuv420p[vIndex++] = (byte) (V < 0 ? 0 : (V > 255 ? 255 : V));
80 | }
81 |
82 | }
83 | }
84 | return yuv420p;
85 | }
86 |
87 | //YUV420p转RGB
88 | public static int[] convertYUV420p2RGB(byte[] yuv, int width, int height) {
89 |
90 | int frameSize = width * height;
91 |
92 | int[] rgb = new int[frameSize];
93 |
94 | int uIndex = frameSize;
95 | int vIndex = frameSize * 5 / 4;
96 |
97 | int a, R, G, B, Y, U, V;
98 | int index = 0;
99 | for (int j = 0; j < height; j++) {
100 | for (int i = 0; i < width; i++) {
101 | // well known RGB to YUV algorithm
102 |
103 | Y = yuv[index] < 0 ? 0x100 + yuv[index] : yuv[index];
104 | U = yuv[uIndex] < 0 ? 0x100 + yuv[uIndex] : yuv[uIndex];
105 | V = yuv[vIndex] < 0 ? 0x100 + yuv[vIndex] : yuv[vIndex];
106 |
107 | R = Y + (V - 128) + (((V - 128) * 103) >> 8);
108 | G = Y - (((U - 128) * 88) >> 8) - (((V - 128) * 183) >> 8);
109 | B = Y + (U - 128) + (((U - 128) * 198) >> 8);
110 |
111 |
112 | R = R > 255 ? 255 : (R < 0 ? 0 : R);
113 | G = G > 255 ? 255 : (G < 0 ? 0 : G);
114 | B = B > 255 ? 255 : (B < 0 ? 0 : B);
115 |
116 | rgb[index] = 0xff000000 + (R << 16) + (G << 8) + B;
117 |
118 | index++;
119 | if (i % 2 != 0) {
120 | uIndex++;
121 | vIndex++;
122 | }
123 | if (i == width - 1 && j % 2 == 0) {//每行最后一个,且这行是第一,三,五
124 | uIndex -= width / 2;
125 | vIndex -= width / 2;
126 | }
127 |
128 | }
129 | }
130 | return rgb;
131 | }
132 |
133 | public static Bitmap convertYUV420sp2RGB(byte[] yuv, int width, int height) {
134 | //YUV420sp转RGB数据 5-60ms
135 | ByteArrayOutputStream out = new ByteArrayOutputStream();
136 | YuvImage yuvImage = new YuvImage(yuv, ImageFormat.NV21, width, height, null);
137 | yuvImage.compressToJpeg(new Rect(0, 0, width, height), 100, out);
138 | byte[] imageBytes = out.toByteArray();
139 | return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
140 | }
141 |
142 |
143 | }
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/java/com/hejunlin/videorecord/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.videorecord;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.os.Environment;
6 | import android.os.Handler;
7 | import android.os.Message;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.util.Log;
10 | import android.view.View;
11 | import android.widget.Button;
12 | import android.widget.ProgressBar;
13 | import android.widget.TextView;
14 | import android.widget.Toast;
15 |
16 | import java.io.File;
17 |
18 | public class MainActivity extends AppCompatActivity {
19 |
20 | private static final int TakeVideoCode = 999;
21 | private Button mTakeVideoButton;
22 | private TextView mResultDirTextView;
23 | private String mTempDir;
24 | private VideoCodecModel mVideo;
25 | private ProgressBar mProgressBar;
26 |
27 | private android.os.Handler handler = new Handler() {
28 | @Override
29 | public void handleMessage(Message msg) {
30 | VideoCodecModel mVideo = (VideoCodecModel) msg.obj;
31 | switch (msg.what) {
32 | case VideoCodecTask.PROGRESS:
33 | mProgressBar.setMax(msg.arg2);
34 | mProgressBar.setProgress(msg.arg1);
35 | break;
36 | case VideoCodecTask.START:
37 | Log.d("px", "codec start");
38 | Toast.makeText(MainActivity.this, "时间戳水印开始",Toast.LENGTH_LONG).show();
39 | break;
40 | case VideoCodecTask.COMPLETE:
41 | Log.d("px", "codec complete");
42 | Toast.makeText(MainActivity.this, "时间戳水印已完成",Toast.LENGTH_LONG).show();
43 | break;
44 | case VideoCodecTask.ERROR:
45 | Log.d("px", "codec error");
46 | Toast.makeText(MainActivity.this, "出错啦!",Toast.LENGTH_LONG).show();
47 | break;
48 | case VideoCodecTask.CANCEL:
49 | Log.d("px", "codec cancel");
50 | break;
51 | }
52 | }
53 | };
54 |
55 |
56 | @Override
57 | protected void onCreate(Bundle savedInstanceState) {
58 | super.onCreate(savedInstanceState);
59 | setContentView(R.layout.activity_main);
60 | initView();
61 | initData();
62 | }
63 |
64 | private void initView() {
65 | mResultDirTextView = (TextView) findViewById(R.id.dst);
66 | mTakeVideoButton = (Button) findViewById(R.id.et1);
67 | mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
68 | }
69 |
70 | private void initData() {
71 | mTempDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
72 | mResultDirTextView.setText("加水印后视频地址:" + mTempDir + "watermark.mp4");
73 | }
74 |
75 | public void onTakeVideo(View v) {
76 | String fileCachePath = mTempDir + "test.mp4";
77 | File file = new File(fileCachePath);
78 | if (!file.getParentFile().exists()) {
79 | file.getParentFile().mkdirs();
80 | }
81 | if (file.exists()) {
82 | file.delete();
83 | }
84 | Intent intent = new Intent(this, TakeVideoActivity.class);
85 | intent.putExtra("fileCachePath", fileCachePath);
86 | startActivityForResult(intent, TakeVideoCode);
87 | }
88 |
89 | public void onClick(View v) {
90 | if (mVideo == null) {
91 | Toast.makeText(this, "请拍摄一段视频", Toast.LENGTH_SHORT).show();
92 | return;
93 | }
94 | VideoCodecTask task = new VideoCodecTask(mVideo);
95 | task.setProgressHandler(handler);
96 | task.start();
97 | }
98 |
99 | @Override
100 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
101 | switch (requestCode) {
102 | case TakeVideoCode:
103 | if (resultCode == RESULT_OK) {
104 | mVideo = new VideoCodecModel();
105 | mVideo.dstPath = mTempDir + "watermark.mp4";
106 | String srcPath = data.getStringExtra("fileCachePath");
107 | long videoCreateTime = data.getLongExtra("videoCreateTime", 0);
108 |
109 | mVideo.srcPath = srcPath;
110 | mVideo.videoCreateTime = videoCreateTime;
111 | }
112 | break;
113 | }
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/java/com/hejunlin/videorecord/TakeVideoActivity.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.videorecord;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.graphics.Bitmap;
6 | import android.graphics.ImageFormat;
7 | import android.graphics.PixelFormat;
8 | import android.hardware.Camera;
9 | import android.media.CamcorderProfile;
10 | import android.media.MediaRecorder;
11 | import android.media.ThumbnailUtils;
12 | import android.net.Uri;
13 | import android.os.Build;
14 | import android.os.Bundle;
15 | import android.os.Handler;
16 | import android.os.Message;
17 | import android.provider.MediaStore;
18 | import android.util.DisplayMetrics;
19 | import android.util.Log;
20 | import android.view.Gravity;
21 | import android.view.SurfaceHolder;
22 | import android.view.SurfaceView;
23 | import android.view.View;
24 | import android.view.Window;
25 | import android.view.WindowManager;
26 | import android.widget.Button;
27 | import android.widget.FrameLayout;
28 | import android.widget.ProgressBar;
29 | import android.widget.TextView;
30 |
31 |
32 | import java.io.File;
33 | import java.io.FileNotFoundException;
34 | import java.io.FileOutputStream;
35 | import java.io.IOException;
36 | import java.lang.reflect.Method;
37 | import java.text.SimpleDateFormat;
38 | import java.util.Date;
39 | import java.util.List;
40 | import java.util.Timer;
41 | import java.util.TimerTask;
42 |
43 | public class TakeVideoActivity extends Activity implements SurfaceHolder.Callback, View.OnClickListener {
44 |
45 | private static final String TAG = "TakeVideoActivity";
46 | private String fileCachePath;
47 | private long videoCreateTime;
48 | private SurfaceView surfaceView;
49 | private Button recordButton;
50 | private Button unRecordButton;
51 | private Button previewButton;
52 | private TextView timeSecondView, curTimeView; //显示时间的文本框
53 | private ProgressBar progressBar;
54 | private MediaRecorder mRecorder;
55 |
56 | private Camera mCamera;
57 | private int mPreviewWidth;
58 | private int mPreviewHeight;
59 | private State mState = State.NONE;
60 | private Camera.Parameters mParameters;
61 |
62 | private enum State {
63 | NONE, PRIVIEW, RECORDE, COMPLETE;
64 | }
65 |
66 | @Override
67 | public void onCreate(Bundle savedInstanceState) {
68 | //全屏
69 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
70 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //应用运行时,保持屏幕高亮,不锁屏
71 | super.onCreate(savedInstanceState);
72 | getWindow().requestFeature(Window.FEATURE_NO_TITLE);
73 | setContentView(R.layout.activity_take_video);
74 |
75 | //获取控件
76 | surfaceView = (SurfaceView) findViewById(R.id.surfaceview);
77 | recordButton = (Button) findViewById(R.id.btn_start_record);
78 | unRecordButton = (Button) findViewById(R.id.btn_stop_record);
79 | previewButton = (Button) findViewById(R.id.btn_preview);
80 | recordButton.setOnClickListener(this);
81 | unRecordButton.setOnClickListener(this);
82 | previewButton.setOnClickListener(this);
83 |
84 | timeSecondView = (TextView) findViewById(R.id.time);
85 | curTimeView = (TextView) findViewById(R.id.tv_time);
86 | progressBar = (ProgressBar) findViewById(R.id.progressBar);
87 | progressBar.setMax(MaxDuring);
88 |
89 | SurfaceHolder holder = surfaceView.getHolder();
90 | holder.addCallback(this);
91 | holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
92 |
93 | startTime();
94 |
95 | //获取支持480p视频
96 | initSupportProfile();
97 | DisplayMetrics dm = new DisplayMetrics();
98 | getWindowManager().getDefaultDisplay().getMetrics(dm);
99 | //保持预览和视频长宽比一致,不拉伸压缩失真
100 | surfaceView.setLayoutParams(new FrameLayout.LayoutParams(-1, mVideoHeiht * dm.widthPixels / mVideoWidth, Gravity.TOP));
101 |
102 | fileCachePath = getIntent().getStringExtra("fileCachePath");
103 | }
104 |
105 | @Override
106 | public void surfaceCreated(SurfaceHolder holder) {
107 | try {
108 | mCamera = Camera.open(0);//后置摄像头
109 | mCamera.setDisplayOrientation(90); // Portrait mode
110 | mCamera.setPreviewDisplay(holder);
111 | mCamera.startPreview();
112 | } catch (Exception e) {
113 | Log.w(TAG, "Can not openDriver: " + e.getMessage());
114 | mCamera.stopPreview();
115 | mCamera.release();
116 | }
117 | }
118 |
119 | @Override
120 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
121 | Log.d(TAG, "surfaceChanged");
122 | if (hasResult) {
123 | return;
124 | }
125 | if (holder.getSurface() == null) {
126 | Log.e(TAG, "Error: preview surface does not exist");
127 | return;
128 | }
129 | mPreviewWidth = mCamera.getParameters().getPreviewSize().width;
130 | mPreviewHeight = mCamera.getParameters().getPreviewSize().height;
131 | Log.d(TAG, "mPreviewWidth=" + mPreviewWidth + ",mPreviewHeight=" + mPreviewHeight);
132 | Log.d(TAG, "surfaceChanged() is called");
133 | try {
134 | mCamera.autoFocus(new Camera.AutoFocusCallback() {
135 | @Override
136 | public void onAutoFocus(boolean success, Camera camera) {
137 | if(success){
138 | initCamera();
139 | camera.cancelAutoFocus();
140 | }
141 | }
142 | });
143 | } catch (Exception e){
144 | Log.d(TAG, "Error starting camera preview: " + e.getMessage());
145 | }
146 | }
147 |
148 | private void initCamera() {
149 | mParameters = mCamera.getParameters();
150 | mParameters.setPictureFormat(PixelFormat.JPEG);
151 | mParameters.setPictureSize(1080,1920);
152 | mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
153 | mParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
154 | setDispaly(mParameters, mCamera);
155 | mCamera.setParameters(mParameters);
156 | mCamera.startPreview();
157 | mCamera.cancelAutoFocus();
158 | }
159 |
160 | private void setDispaly(Camera.Parameters parameters,Camera camera) {
161 | if (Integer.parseInt(Build.VERSION.SDK) >= 8){
162 | setDisplayOrientation(camera,90);
163 | } else {
164 | parameters.setRotation(90);
165 | }
166 | }
167 |
168 | private void setDisplayOrientation(Camera camera, int i) {
169 | Method downPolymorphic;
170 | try{
171 | downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[]{int.class});
172 | if(downPolymorphic!=null) {
173 | downPolymorphic.invoke(camera, new Object[]{i});
174 | }
175 | }
176 | catch(Exception e){
177 | Log.e(TAG, "image error");
178 | }
179 | }
180 |
181 | @Override
182 | public void surfaceDestroyed(SurfaceHolder holder) {
183 | Log.d(TAG, "surfaceDestroyed");
184 | if (mCamera != null) {
185 | try {
186 | mCamera.setPreviewDisplay(null);
187 | } catch (IOException e) {
188 | e.printStackTrace();
189 | }
190 | mCamera.stopPreview();
191 | mCamera.release();
192 | }
193 | }
194 |
195 | @Override
196 | protected void onDestroy() {
197 | super.onDestroy();
198 | try {
199 | task.cancel();
200 | timer.cancel();
201 | if (mCamera != null) {
202 | mCamera.setPreviewDisplay(null);
203 | mCamera.stopPreview();
204 | mCamera.release();
205 | }
206 | } catch (Exception e) {
207 | e.printStackTrace();
208 | }
209 |
210 | }
211 |
212 | @Override
213 | public void onClick(View v) {
214 | int id = v.getId();
215 | try {
216 | if (id == R.id.btn_start_record) {
217 | startRecorder();
218 | } else if (id == R.id.btn_stop_record) {
219 | if (mState == State.RECORDE)
220 | stopRecorder();
221 | else if (mState == State.COMPLETE)
222 | skipToCodec();
223 | } else if (id == R.id.btn_preview) {
224 | previewVideo();
225 | }
226 | } catch (Exception e) {
227 | e.printStackTrace();
228 | if (mCamera != null) {
229 | try {
230 | mCamera.setPreviewDisplay(null);
231 | } catch (IOException e1) {
232 | e1.printStackTrace();
233 | }
234 | mCamera.stopPreview();
235 | mCamera.release();
236 | }
237 | }
238 | }
239 |
240 | private void startRecorder() {
241 | if (mState == State.RECORDE) {
242 | return;
243 | }
244 | if (mState == State.COMPLETE) {
245 | mCamera.startPreview();//重拍启动预览,这里主要启动对焦程序,如果不启动,则manager不知道已经启动,在stop的时候不会关闭预览
246 | }
247 | // 关闭预览并释放资源
248 | Camera c = mCamera;
249 | c.unlock();
250 |
251 | mRecorder = new MediaRecorder();
252 | mRecorder.reset();
253 |
254 | mRecorder.setCamera(c);
255 | mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
256 | mRecorder.setProfile(CamcorderProfile.get(mQuality));
257 |
258 | //设置选择角度,顺时针方向,因为默认是逆向度的,这样图像就是正常显示了,这里设置的是观看保存后的视频的角度
259 | mRecorder.setOrientationHint(90);
260 | videoCreateTime = System.currentTimeMillis();
261 | Log.d(TAG, "video cache path:" + fileCachePath);
262 | try {
263 | File file = new File(fileCachePath);
264 | if (!file.getParentFile().exists()) file.getParentFile().mkdirs();
265 | if (file.exists()) file.delete();
266 | file.createNewFile();
267 |
268 | mRecorder.setOutputFile(file.getAbsolutePath());
269 | } catch (IOException e) {
270 | e.printStackTrace();
271 | }
272 | try {
273 | mRecorder.prepare();
274 | mRecorder.start();
275 | } catch (Exception e) {
276 | e.printStackTrace();
277 | }
278 | mState = State.RECORDE;
279 | unRecordButton.setVisibility(View.VISIBLE);
280 | recordButton.setVisibility(View.GONE);
281 | previewButton.setVisibility(View.GONE);
282 | unRecordButton.setText("停止");
283 | }
284 |
285 |
286 | private void stopRecorder() {
287 | if (mState == State.RECORDE) {
288 | //停止录制
289 | mRecorder.stop();
290 | //释放资源
291 | mRecorder.release();
292 | mRecorder = null;
293 | mCamera.stopPreview();
294 |
295 | mState = State.COMPLETE;
296 | previewButton.setVisibility(View.VISIBLE);
297 | unRecordButton.setVisibility(View.VISIBLE);
298 | recordButton.setVisibility(View.VISIBLE);
299 | unRecordButton.setText("完成");
300 | recordButton.setText("重拍");
301 | }
302 | }
303 |
304 | private void previewVideo() {
305 | //预览录像
306 | Intent intent = new Intent(Intent.ACTION_VIEW);
307 | String type = "video/mp4";
308 | Uri uri = Uri.parse("file://" + fileCachePath);
309 | intent.setDataAndType(uri, type);
310 | startActivity(intent);
311 | }
312 |
313 | private void skipToCodec() {
314 |
315 | //告诉调用者结果
316 | Intent intent = new Intent();
317 | intent.putExtra("fileCachePath", fileCachePath);
318 | intent.putExtra("videoCreateTime", videoCreateTime);
319 | String thumpPath = new String(fileCachePath);
320 |
321 | thumpPath = thumpPath.replace(".mp4", ".jpg");
322 | thumpPath = thumpPath.replace("/video/", "/thump/");
323 | Log.d(TAG, "thumpPath=" + thumpPath);
324 | saveBitmapWithName(getVideoThumbnail(fileCachePath), thumpPath);
325 | intent.putExtra("thumpPath", thumpPath);
326 |
327 | setResult(RESULT_OK, intent);
328 | finish();
329 |
330 | }
331 |
332 | private boolean hasResult = false;
333 |
334 | @Override
335 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
336 | if (requestCode == 0x123 && resultCode == RESULT_OK) {
337 | hasResult = true;
338 | Intent intent = new Intent();
339 | intent.putExtra("fileCachePath", fileCachePath);
340 | setResult(RESULT_OK, intent);
341 | new File(fileCachePath).delete();
342 | handler.postDelayed(new Runnable() {
343 | @Override
344 | public void run() {
345 | finish();
346 | }
347 | }, 250);
348 | }
349 | }
350 |
351 | //////////////////显示时间信息的代码
352 | SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
353 | Timer timer = new Timer();
354 | private int curTimeSecond = MaxDuring;
355 | private static final int MaxDuring = 60;
356 | TimerTask task = new TimerTask() {
357 | @Override
358 | public void run() {
359 | String s = format.format(new Date());
360 | handler.obtainMessage(CHANGE_TIME, s).sendToTarget();
361 | }
362 | };
363 |
364 | private static final int CHANGE_TIME = 111;
365 | Handler handler = new Handler() {
366 | @Override
367 | public void handleMessage(Message msg) {
368 | switch (msg.what) {
369 | case CHANGE_TIME:
370 | if (mState == State.RECORDE) {
371 | curTimeSecond--;
372 | if (curTimeSecond == 0) {
373 | stopRecorder();
374 | return;
375 | }
376 | if (timeSecondView.getVisibility() != View.VISIBLE) {
377 | timeSecondView.setVisibility(View.VISIBLE);
378 | }
379 | timeSecondView.setText(secondToText(curTimeSecond));
380 | progressBar.setProgress(MaxDuring - curTimeSecond);
381 | } else if (timeSecondView.getVisibility() == View.VISIBLE) {
382 | timeSecondView.setVisibility(View.INVISIBLE);
383 | curTimeSecond = MaxDuring;
384 | progressBar.setProgress(0);
385 | }
386 | curTimeView.setText(msg.obj.toString());
387 | break;
388 | }
389 | }
390 | };
391 |
392 | String secondToText(int second) {
393 | if (second < 10) {
394 | return " 00:0" + second;
395 | } else if (second < 60) {
396 | return " 00:" + second;
397 | } else {
398 | return " 01:" + second % 60;
399 | }
400 | }
401 |
402 | @Override
403 | public void onBackPressed() {
404 | if (mState != State.RECORDE) {
405 | setResult(RESULT_CANCELED);
406 | finish();
407 | }
408 | }
409 |
410 | void startTime() {
411 | timer.schedule(task, 0, 1000);
412 | }
413 |
414 | private int mQuality = -1;
415 |
416 | private void showSupportVideoSize(Camera camera) {
417 | Camera.Parameters p = camera.getParameters();
418 | List videoSizes = p.getSupportedVideoSizes();
419 | if (videoSizes != null) {
420 | StringBuilder sb = new StringBuilder("SupportedVideoSizes:[");
421 | for (Camera.Size s : videoSizes) {
422 | sb.append(s.width).append("*").append(s.height).append(",");
423 | }
424 | Log.d(TAG, sb.deleteCharAt(sb.length() - 1).toString());
425 | } else {
426 | Log.d(TAG, "SupportedVideoSizes:null");
427 | }
428 | List formats = p.getSupportedPreviewFormats();
429 | if (formats.contains(ImageFormat.NV21))
430 | p.setPreviewFormat(ImageFormat.NV21);
431 | }
432 |
433 | private int mVideoWidth, mVideoHeiht;
434 |
435 | private void initSupportProfile() {
436 |
437 | if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_TIME_LAPSE_480P)) {//无声音的480p
438 | mQuality = CamcorderProfile.QUALITY_TIME_LAPSE_480P;
439 | } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_TIME_LAPSE_QVGA)) {
440 | mQuality = CamcorderProfile.QUALITY_TIME_LAPSE_QVGA;
441 | } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_TIME_LAPSE_CIF)) {
442 | mQuality = CamcorderProfile.QUALITY_TIME_LAPSE_CIF;
443 | } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_TIME_LAPSE_720P)) {
444 | mQuality = CamcorderProfile.QUALITY_TIME_LAPSE_720P;
445 | }
446 | Log.d(TAG, "finally mQuality resolution:" + mQuality);
447 | CamcorderProfile profile = CamcorderProfile.get(mQuality);
448 | //因为竖屏被旋转了90度
449 | mVideoHeiht = profile.videoFrameWidth;
450 | mVideoWidth = profile.videoFrameHeight;
451 | Log.d(TAG, "video screen from CamcorderProfile resolution:" + mVideoWidth + "*" + mVideoHeiht);
452 | }
453 |
454 | public static Bitmap getVideoThumbnail(String filePath) {
455 | return ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Images.Thumbnails.MINI_KIND);
456 | }
457 |
458 | public static void saveBitmapWithName(Bitmap bitmap, String path) {
459 | FileOutputStream outputStream = null;
460 | try {
461 | File file = new File(path);
462 | if (!file.getParentFile().exists()) {
463 | file.getParentFile().mkdirs();
464 | }
465 | file.createNewFile();
466 | outputStream = new FileOutputStream(file);
467 | } catch (FileNotFoundException e) {
468 | e.printStackTrace();
469 | } catch (IOException e) {
470 | e.printStackTrace();
471 | }
472 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
473 | }
474 | }
475 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/java/com/hejunlin/videorecord/VideoCodecModel.java:
--------------------------------------------------------------------------------
1 | package com.hejunlin.videorecord;
2 |
3 | import java.io.Serializable;
4 |
5 | public class VideoCodecModel implements Serializable {
6 |
7 | private static final long serialVersionUID = -1307249622002520298L;
8 | public String srcPath;
9 | public String dstPath;
10 | public long videoCreateTime;
11 | public int id;
12 |
13 |
14 | public VideoCodecModel() {
15 | }
16 |
17 | public String getSrcPath() {
18 | return srcPath;
19 | }
20 |
21 | public void setSrcPath(String srcPath) {
22 | this.srcPath = srcPath;
23 | }
24 |
25 | public String getDstPath() {
26 | return dstPath;
27 | }
28 |
29 | public void setDstPath(String dstPath) {
30 | this.dstPath = dstPath;
31 | }
32 |
33 | public long getVideoCreateTime() {
34 | return videoCreateTime;
35 | }
36 |
37 | public void setVideoCreateTime(long videoCreateTime) {
38 | this.videoCreateTime = videoCreateTime;
39 | }
40 |
41 | @Override
42 | public boolean equals(Object o) {
43 | if (this == o) return true;
44 | if (!(o instanceof VideoCodecModel)) return false;
45 |
46 | VideoCodecModel that = (VideoCodecModel) o;
47 |
48 | if (videoCreateTime != that.videoCreateTime) return false;
49 | if (!srcPath.equals(that.srcPath)) return false;
50 | return dstPath.equals(that.dstPath);
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/drawable/diverde.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/drawable/litte_red_point.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/drawable/play.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/drawable/play1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/VideoWaterMarkSample/app/src/main/res/drawable/play1.png
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/drawable/play2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/VideoWaterMarkSample/app/src/main/res/drawable/play2.png
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/drawable/progressbar_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 | -
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | -
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
17 |
18 |
26 |
27 |
34 |
35 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/layout/activity_take_video.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
17 |
18 |
26 |
27 |
28 |
29 |
37 |
38 |
45 |
46 |
55 |
56 |
57 |
58 |
59 |
70 |
71 |
82 |
83 |
91 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/VideoWaterMarkSample/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/VideoWaterMarkSample/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/mipmap-xhdpi/capture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/VideoWaterMarkSample/app/src/main/res/mipmap-xhdpi/capture.png
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/VideoWaterMarkSample/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/VideoWaterMarkSample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/VideoWaterMarkSample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | VideoWaterMarkSample
3 |
4 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.0.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Fri Mar 03 17:00:18 CST 2017
16 | systemProp.http.proxyHost=mirrors.neusoft.edu.cn
17 | systemProp.http.proxyPort=80
18 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/VideoWaterMarkSample/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/VideoWaterMarkSample/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | #Fri Feb 23 16:17:03 CST 2018
11 | ndk.dir=G\:\\E\\Android\\sdk\\ndk-bundle
12 | sdk.dir=G\:\\E\\Android\\sdk
13 |
--------------------------------------------------------------------------------
/VideoWaterMarkSample/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/images/camera3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/images/camera3.gif
--------------------------------------------------------------------------------
/images/camera5.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/images/camera5.gif
--------------------------------------------------------------------------------
/images/guard3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/images/guard3.gif
--------------------------------------------------------------------------------
/images/mediacodec.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/images/mediacodec.gif
--------------------------------------------------------------------------------
/images/mediaplayer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartyuge/MultiMediaSample/bae3c082f98b7ee2313a92da1ee6f0ae1c29f9bc/images/mediaplayer.png
--------------------------------------------------------------------------------