Skip to content

Commit

Permalink
Fixing bug: share in Nougat and above
Browse files Browse the repository at this point in the history
  • Loading branch information
cergo123 committed Sep 6, 2019
1 parent 789031e commit 266b9c3
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 20 deletions.
116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<p align="center">
<img src="https://user-images.githubusercontent.com/41321155/56833705-e8f0c180-6877-11e9-88fb-36a3ee17f149.gif"><br>
<img src="https://user-images.githubusercontent.com/41321155/56833705-e8f0c180-6877-11e9-88fb-36a3ee17f149.gif"><br><br>
<img width="300" src="https://user-images.githubusercontent.com/41321155/64449466-a7570980-d0e8-11e9-8c45-02a53951763d.png"><br><br>
<img src="https://user-images.githubusercontent.com/41321155/56834806-1b4fee00-687b-11e9-9694-e6ce3bc2a94d.png">

</p>


Expand All @@ -10,12 +12,19 @@ An Android library to make the implementation of voice/audio messages' playing e
# Why to use this library?
- To avoid the unwanted errors of using MediaPlayer in Android
- This is a ready-to-use component to use in playing the chat voice messages in chat applications or any other app
- Easy to use WaveForm for the played sounds

# Features
- Extremely easy to use
- Direct share of the audio file
- Full control of customization (colors, visibilities, shapes)
- The controls are availabe in XML and programmatically
- WaveForm Seekbar

# What's new in `1.0.2`
- Adding Waveform Seekbar (Sound Visualization)
- Adding Timing Background Color
- Fixing a minor error

# Installation
Step 1. Add it in your root build.gradle at the end of repositories:
Expand All @@ -29,7 +38,7 @@ Step 1. Add it in your root build.gradle at the end of repositories:
Step 2. Add the dependency

dependencies {
implementation 'com.github.JagarYousef:ChatVoicePlayer:1.0.0'
implementation 'com.github.JagarYousef:ChatVoicePlayer:1.0.2'
}

# Usage
Expand All @@ -39,17 +48,21 @@ Step 2. Add the dependency
android:id="@+id/voicePlayerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:playPauseBackgroundColor="#4CAF50"
app:shareBackgroundColor="#F44336"
app:viewBackground="@color/gray"
app:enableVisualizer="true"
app:visualizationPlayedColor="#ff7700"
app:visualizationNotPlayedColor="#727171"
app:playPauseBackgroundColor="#ff7700"
app:timingBackgroundColor="#6AFF7700"
app:seekBarProgressColor="#000"
app:showShareButton="true"
app:shareCornerRadius="100"
app:playPauseCornerRadius="100"
app:showTiming="false"
app:showTiming="true"
app:viewCornerRadius="100"
app:progressTimeColor="@color/pink"
app:viewBackground="#C6C4CF"
app:progressTimeColor="#000"
app:seekBarThumbColor="#FFC107"
app:seekBarProgressColor="#000"
app:shareBackgroundColor="#ff7700"
app:shareText="SHARE ME"/>
```
2. Now prepare your player view wherever you want in your activity:
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(path: ':chatvoiceplayerlibrary')


}

12 changes: 9 additions & 3 deletions app/src/main/java/me/jagar/chatvoiceplayer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import java.io.File;

Expand All @@ -25,24 +26,29 @@ protected void onCreate(Bundle savedInstanceState) {
voicePlayerView = findViewById(R.id.voicePlayerView);
checkPermissions();
voicePlayerView.setAudio(Environment.getExternalStorageDirectory().getPath() + File.separator + "song.mp3");
if ((new File(Environment.getExternalStorageDirectory().getPath() + File.separator + "song.mp3")).exists()){
Log.e("EXIST", "SONG EXISTS");
}else{
Log.e("DOESNT EXIST", Environment.getExternalStorageDirectory().getPath() + File.separator + "song.mp3");
}
}

private void checkPermissions() {
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.READ_CONTACTS)
Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {

// Permission is not granted
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
Manifest.permission.READ_CONTACTS)) {
Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed; request the permission
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE},
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_WRITE_EXTERNAL_STORAGE);

// MY_PERMISSIONS_REQUEST_READ_WRITE_EXTERNAL_STORAGE is an
Expand Down
14 changes: 11 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<me.jagar.chatvoiceplayerlibrary.VoicePlayerView
android:id="@+id/voicePlayerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:playPauseBackgroundColor="#4CAF50"
app:enableVisualizer="true"
app:visualizationPlayedColor="#ff7700"
app:visualizationNotPlayedColor="#727171"
app:playPauseBackgroundColor="#ff7700"
app:timingBackgroundColor="#6AFF7700"
app:seekBarProgressColor="#000"
app:showShareButton="true"
app:shareCornerRadius="100"
app:playPauseCornerRadius="100"
app:showTiming="false"
app:showTiming="true"
app:viewCornerRadius="100"
app:progressTimeColor="@color/pink"
app:viewBackground="#C6C4CF"
app:progressTimeColor="#000"
app:seekBarThumbColor="#FFC107"
app:shareBackgroundColor="#ff7700"
app:shareText="SHARE ME"/>
</LinearLayout>
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.android.tools.build:gradle:3.4.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -18,6 +18,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.jagar.chatvoiceplayerlibrary;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileUtils {
public static byte[] fileToBytes(File file) {
int size = (int) file.length();
byte[] bytes = new byte[size];
try {
BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
buf.read(bytes, 0, bytes.length);
buf.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return bytes;
}
}
Loading

0 comments on commit 266b9c3

Please sign in to comment.