All Projects → rygelouv → android-audio-sensei

rygelouv / android-audio-sensei

Licence: Apache-2.0 license
High-level library to make android audio recording and playing more simple by handling boring stuff like runtime permissions and by completely abstracting audio playback controller

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to android-audio-sensei

Vienna
Vienna 是一款安卓音频操作工具,主要提供音频录制与播放的功能。提供简洁的接口降低音频开发的成本。
Stars: ✭ 43 (+4.88%)
Mutual labels:  audio-player, audio-recorder
flutter sound
Flutter plugin for sound. Audio recorder and player.
Stars: ✭ 727 (+1673.17%)
Mutual labels:  audio-player, audio-recorder
CallRecorder
SW Call Recorder is an Android app that records phone calls based on user selected phone numbers.
Stars: ✭ 56 (+36.59%)
Mutual labels:  audio-player, audio-recorder
SoundDeck
Sound Deck is a powerful audio-focused plugin for the Elgato Stream Deck.
Stars: ✭ 20 (-51.22%)
Mutual labels:  audio-player, audio-recorder
hermes-audio-server
An open source implementation of the audio server part of the Hermes protocol
Stars: ✭ 23 (-43.9%)
Mutual labels:  audio-player, audio-recorder
Miza
A multipurpose Discord bot.
Stars: ✭ 61 (+48.78%)
Mutual labels:  audio-player
facet
Facet is a live coding system for algorithmic music
Stars: ✭ 72 (+75.61%)
Mutual labels:  audio-player
rAudio-1
Raspberry Pi audio player: AirPlay, Audio CD, Bluetooth, DAB radio, DSP, Internet rafio, Multi-room, Spotify Connect, UPnP
Stars: ✭ 151 (+268.29%)
Mutual labels:  audio-player
react-808
808 Drum Machine built using React.js hooks API
Stars: ✭ 51 (+24.39%)
Mutual labels:  audio-player
ad-alexatalkingclock
Alexa (or other Smart Speakers) tell you the time without asking every hour. Please ⭐️if you like my app :)
Stars: ✭ 30 (-26.83%)
Mutual labels:  mediaplayer
bPlayer
A great replacement for audio elements
Stars: ✭ 68 (+65.85%)
Mutual labels:  audio-player
VKAudioPlayer
VK Audio Player on Delphi
Stars: ✭ 16 (-60.98%)
Mutual labels:  audio-player
MusicPlayer
Android music player example.
Stars: ✭ 20 (-51.22%)
Mutual labels:  mediaplayer
vue-dictaphone
🎙️ Vue.js dictaphone component to record audio from the user
Stars: ✭ 22 (-46.34%)
Mutual labels:  audio-recorder
MusicPlayer
Play songs in Background with a set of user preferences available as a 'switch' in the cmdlet.
Stars: ✭ 16 (-60.98%)
Mutual labels:  mediaplayer
AudioAnchor
Android audio player that tracks the listening progress of your audio books and podcasts
Stars: ✭ 167 (+307.32%)
Mutual labels:  audio-player
Maple
Maple is a windows desktop application designed to support semi and non professional streamers in playing back local audio files and streaming content from the internet to their favorite playback device
Stars: ✭ 37 (-9.76%)
Mutual labels:  mediaplayer
HPlayer2
Modular Media Player for Raspberry Pi and more...
Stars: ✭ 28 (-31.71%)
Mutual labels:  mediaplayer
reco
A simple audio recording app for modern Linux desktop environment like Pantheon
Stars: ✭ 47 (+14.63%)
Mutual labels:  audio-recorder
violin
🎵 Minimalistic music player for desktop devices.
Stars: ✭ 40 (-2.44%)
Mutual labels:  audio-player

Introduction

Android Audio Sensei is a high-level library that aims to make working with audio on Android more simple. The reason is simple, when it comes to work with audio there is a lot of work to do before to get the feature you want for example:

  • Requesting permission before recording audio
  • Handling the permission when granted
  • Handling playback control (pause, play, stop) on the MediaPlayer with your UI
  • Reporting the media playing progress using a seekbar or something similar
  • Ensure to release the MediaPlayer when not needed anymore

When it comes to do the same audio playing in a list like a Recyclerview, this becomes more complicated

  • Stop and reset the current playing audio before playing another
  • As Recyclerview's items are not directly bounded to the Activity/Fragment lifecycle, releasing the MediaPlayer may become a problem
  • Most of the times on list of audio track (like in an Audion Player app or a chat app like whatsapp), wen you play hit the pause button, the play button appear and vice versa. Doing the same thing in a list items is a bit problematic
  • Etc...

Audio Sensei take care of all of this for you and provide a very simple way to record and play audio even in a Recyclerview

AudioSensei library does not use any other library to do its job

In your project root build.gradle with:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

and in the app or module build.gradle:

dependencies {
    compile 'com.github.rygelouv:android-audio-sensei:0.1.2'
}

Recording audio

You simply need an instance of AudioSensei class to start recording

Using Recorder()

AudioSensei.Recorder()
        .with(MainActivity.this)
        .name("file_name")
        .to(AudioRecordInfo.AudioPath.APP_PUBLIC_MUSIC)
        .start();

Handling runtime permission

When call startRecording(), AudioSensei check first if the RECORD_AUDIO permission is granted if not the permission is requested so you don't have to do it yourself.

To make sure the AudioSensei will start recording after the permission is granted, you need to override the method onRequestPermissionsResult and tell AudioSensei to do the rest

@Override
public void onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) {
    AudioSensei.getInstance().onRequestPermissionsResult(requestCode, permissions, grantResults);
}

Stop or cancel recording

AudioSensei.getInstance().stopRecording(); // Call this when you are done recording
AudioSensei.getInstance().cancelRecording(); // when the recorder is stopped, AudioSensei does not record any file

Get the last recorded file

To get the last file you just recorded just after the record stop

AudioSensei.getInstance().getLastRecordedOutputFile()

Create a player view

Most of the time an audio player just follow the same pattern. You have 2 buttons, Play and Pause, sometimes the stop button and the view that indicate the progress which mostly a SeekBar. After creating the view most of the next step is to get an instance of MediaPlayer and play/pause/stop depending on which button is clicked. Handling the progress is done by using MediaPlayer.getCurrentPosition()

Now gess what you don't need to do any of that now. With AudioSensei library, you can just do this:

<com.rygelouv.audiosensei.player.AudioSenseiPlayerView
        android:id="@+id/audio_player"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

Even when you put this as item for a Recyclerview, nothing changes. AudioSensei knows if a media is being played and will stop the current media in order to play the new one.

Provide an Audio target

AudioSensei library considers any sound to play as a target be it remote sound (on the internet) or local sound file (on the phone). To set a target you just need to call one of the implementation of the method setAudioTarget

setAudioTarget(String url) // If you want to play remote file in streaming mode. Can also be used for local files
setAudioTarget(int resource) // If you want to play resource in your android project or APK
setAudioTarget(Uri uri) // If you want to play a local file on the user disk storage

You just set a target and you're done!

Using with recyclerView

If you are using AudioSenseiPlayerView in recyclerview, you must tell AudioSensei to track down the lifecycle by adding this code:

AudioSenseiListObserver.getInstance().registerLifecycle(getLifecycle());

Add custom layout

If you want to add you owm custom design (i encourage you to do so), you just need to provide your layout file via the attribute app:custom_layout="@layout/custom_player"

<com.rygelouv.audiosensei.player.AudioSenseiPlayerView
        android:id="@+id/audio_player"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:custom_layout="@layout/custom_player"
        />

To make this work properly you need to provide same id for player views:

  • button_play : For play button
  • button_pause: For pause button
  • seekbar_audio: For SeekBar that shows audio progress

Register click listeners for the view inside your custom layout

If you added a custom layout as i just shown above, perhaps you gonna need to perform clicks on views inside that custom layout of yours. So to do that, you need to register click listener for your views in AudioSenSeiPlayerView by specifying the view that you want to handle the click and the callback using OnPlayerViewClickListenerlike this:

audioSenseiPlayerView1.registerViewClickListener(R.id.stop, new OnPlayerViewClickListener()
        {
            @Override
            public void onPlayerViewClick(View view)
            {
                Log.i(TAG, "onPlayer view Clicked");
                audioSenseiPlayerView1.stop();
            }
        });

Here, we registered a click for a stop custom actions that we added in the custom layout as the stop button is not provided by default in AudioSenseiPlayerView

After registering the view and the call back, YOU MUST CALL commitClickEvents otherwise your events won't be triggered.

audioSenseiPlayerView1.commitClickEvents();

Get the player rootView

If you want to manipulate the views inside the player yourselft you can get it's rootView

View playerRootView = audioSenseiPlayerView1.getPlayerRootView();

Proguard

If you are using proguard, you need to add this line in your proguard-rules.pro file

-dontwarn com.rygelouv.audiosensei.**

TODO

This is library is still in active development. So you may encounter some bugs please create issues. This is what remains :

  • Handle Audio Focus
  • Fix some bugs
  • Allow to play audio in a background Service to keep playing even when the user leave the app or the current page and provide controls in a notification

Credits

Author: Rygel Louv http://www.rygelouv.wordpress.com/

License

Copyright 2017 Rygelouv.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].