Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace old audio visualizer #16

Merged
merged 3 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ android {
android.sourceSets.main.jniLibs.srcDirs = ['libs']

dependencies {
implementation 'com.gauravk.audiovisualizer:audiovisualizer:0.9.1'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.chibde:audiovisualizer:2.0.1'
testImplementation 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.media.audiofx.BassBoost;
import android.media.audiofx.LoudnessEnhancer;
import android.os.Build;
import android.os.Bundle;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.support.annotation.RequiresApi;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
Expand All @@ -27,13 +26,13 @@
import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.TextView;
import com.chibde.visualizer.BarVisualizer;

import com.gauravk.audiovisualizer.visualizer.BarVisualizer;

public class LiveWithSettings extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

private BarVisualizer mVisualizer;
private BarVisualizer barVisualizer;
private HapticFeedback hapticFeedback;
private MediaPlayer mAudioPlayer;
private Vibrator vibrator;
Expand Down Expand Up @@ -215,47 +214,61 @@ private void requestVisualizerPermissions() {
}

private void initializeVisualizerAndFeedback() {
mVisualizer = findViewById(R.id.bar);
hapticFeedback = initHapticFeedback();

mAudioPlayer = MediaPlayer.create(this, recordedSongId);
Thread t = new Thread(hapticFeedback);
t.start();
mAudioPlayer.start();
initVisualizer();
}

private void initVisualizer() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I like how this is much cleaner than before. good call!

barVisualizer = findViewById(R.id.visualizer);
//barVisualizer.setColor(Color.argb(1, Color.red(219), Color.green(24), Color.blue(103)));
barVisualizer.setDensity(40);
barVisualizer.setPlayer(mAudioPlayer.getAudioSessionId());
}

private HapticFeedback initHapticFeedback() {
HapticFeedback songHapticFeedback = null;
switch (recordedSongId) {
case R.raw.croatian:
hapticFeedback = new HapticFeedback(80,618);
songHapticFeedback = new HapticFeedback(80,618);
break;
case R.raw.highscore:
hapticFeedback = new HapticFeedback(100, 538);
songHapticFeedback = new HapticFeedback(100, 538);
break;
case R.raw.unity:
hapticFeedback = new HapticFeedback(100, 555);
songHapticFeedback = new HapticFeedback(100, 555);
break;
case R.raw.christmas:
hapticFeedback = new HapticFeedback(90, 530);
songHapticFeedback = new HapticFeedback(90, 530);
break;
case R.raw.grilboyfriend:
hapticFeedback = new HapticFeedback(90, 520);
songHapticFeedback = new HapticFeedback(90, 520);
break;
case R.raw.forever:
hapticFeedback = new HapticFeedback(100, 565);
songHapticFeedback = new HapticFeedback(100, 565);
break;
case R.raw.alreadygone:
hapticFeedback = new HapticFeedback(100, 575);
songHapticFeedback = new HapticFeedback(100, 575);
break;
case R.raw.doesntmatter:
hapticFeedback = new HapticFeedback(100, 600);
songHapticFeedback = new HapticFeedback(100, 600);
break;
case R.raw.walkaway:
hapticFeedback = new HapticFeedback(100, 600);
songHapticFeedback = new HapticFeedback(100, 600);
break;
case R.raw.enen:
hapticFeedback = new HapticFeedback(100, 620);
songHapticFeedback = new HapticFeedback(100, 620);
break;
default:
songHapticFeedback = null;
break;
}
Thread t = new Thread(hapticFeedback);
t.start();
mAudioPlayer.start();

int audioSessionId = mAudioPlayer.getAudioSessionId();
if (audioSessionId != -1)
mVisualizer.setAudioSessionId(audioSessionId);
return songHapticFeedback;
}

@Override
Expand Down Expand Up @@ -303,8 +316,6 @@ public boolean onNavigationItemSelected(MenuItem item) {
@Override
protected void onDestroy() {
super.onDestroy();
if (mVisualizer != null)
mVisualizer.release();
}

private class HapticFeedback implements Runnable {
Expand Down
14 changes: 5 additions & 9 deletions app/src/main/res/layout/content_music.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,10 @@
</LinearLayout>
</com.example.pinkorange.vibrato.FixedTopFadeEdgeScrollView>

<com.gauravk.audiovisualizer.visualizer.BarVisualizer
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:avColor="@color/pink"
app:avDensity="0.8"
app:avSpeed="normal"
app:avType="fill" />
<com.chibde.visualizer.BarVisualizer
android:id="@+id/visualizer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"/>

</android.support.constraint.ConstraintLayout>