项目作者: lykmapipo

项目描述 :
A pack of helpful helpers to gather images, video and audio from media source(s)
高级语言: Java
项目地址: git://github.com/lykmapipo/android-media-provider.git
创建时间: 2019-07-01T09:22:26Z
项目社区:https://github.com/lykmapipo/android-media-provider

开源协议:MIT License

下载


android-media-provider

A pack of helpful helpers to gather images, video and audio from media source(s).

Installation

Add https://jitpack.io to your build.gradle with:

  1. allprojects {
  2. repositories {
  3. maven { url "https://jitpack.io" }
  4. }
  5. }

add android-media-provider dependency into your project

  1. dependencies {
  2. implementation 'com.github.lykmapipo:android-media-provider:v0.3.0'
  3. }

Usage

In activity(or fragment) capture image or record video and audio

  1. public class MainActivity extends AppCompatActivity {
  2. private static final String TAG = MainActivity.class.getSimpleName();
  3. private ImageView ivCapturedImage;
  4. private VideoView vvRecordedVideo;
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_main);
  9. // capture image
  10. ivCapturedImage = findViewById(R.id.ivCapturedImage);
  11. Button captureImageButton = findViewById(R.id.btnCaptureImage);
  12. captureImageButton.setOnClickListener(new View.OnClickListener() {
  13. @Override
  14. public void onClick(View v) {
  15. MediaProvider.captureImage(MainActivity.this, new MediaProvider.OnImageCapturedListener() {
  16. @Override
  17. public void onSuccess(File file, Uri uri) {
  18. ivCapturedImage.setImageURI(uri);
  19. Toast.makeText(MainActivity.this, "Image Captured Success: " + file.getAbsolutePath(), Toast.LENGTH_SHORT).show();
  20. }
  21. @Override
  22. public void onFailure(Exception error) {
  23. Toast.makeText(MainActivity.this, "Image Captured Failed: " + error.getMessage(), Toast.LENGTH_SHORT).show();
  24. }
  25. });
  26. }
  27. });
  28. // record video
  29. vvRecordedVideo = findViewById(R.id.vvRecordedVideo);
  30. Button recordVideoButton = findViewById(R.id.btnRecordVideo);
  31. recordVideoButton.setOnClickListener(new View.OnClickListener() {
  32. @Override
  33. public void onClick(View v) {
  34. MediaProvider.recordVideo(MainActivity.this, new MediaProvider.OnVideoRecordedListener() {
  35. @Override
  36. public void onSuccess(File file, Uri uri) {
  37. vvRecordedVideo.setVideoURI(uri);
  38. vvRecordedVideo.start();
  39. Toast.makeText(MainActivity.this, "Video Recorded Success: " + file.getAbsolutePath(), Toast.LENGTH_SHORT).show();
  40. }
  41. @Override
  42. public void onFailure(Exception error) {
  43. Toast.makeText(MainActivity.this, "Video Recorded Failed: " + error.getMessage(), Toast.LENGTH_SHORT).show();
  44. }
  45. });
  46. }
  47. });
  48. // record audio
  49. Button recordAudioButton = findViewById(R.id.btnRecordAudio);
  50. recordAudioButton.setOnClickListener(new View.OnClickListener() {
  51. @Override
  52. public void onClick(View v) {
  53. MediaProvider.recordAudio(MainActivity.this, new MediaProvider.OnAudioRecordedListener() {
  54. @Override
  55. public void onSuccess(File file, Uri uri) {
  56. Toast.makeText(MainActivity.this, "Audio Record Success: " + file.getAbsolutePath(), Toast.LENGTH_SHORT).show();
  57. }
  58. @Override
  59. public void onFailure(Exception error) {
  60. Toast.makeText(MainActivity.this, "Audio Record Failed: " + error.getMessage(), Toast.LENGTH_SHORT).show();
  61. }
  62. });
  63. }
  64. });
  65. }
  66. }

Test

  1. ./gradlew test

Contribute

It will be nice, if you open an issue first so that we can know what is going on, then, fork this repo and push in your ideas.
Do not forget to add a bit of test(s) of what value you adding.

License

(The MIT License)

Copyright (c) lykmapipo && Contributors

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
‘Software’), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.