AudioPlayerView is an Android view that loads audio from an url and have basic playback tools.

Overview

AudioPlayerView

Android Arsenal Awesome

AudioPlayerView is an Android view that loads audio from an url and have basic playback tools.

It makes use of the Android MediaPlayer library.

alt text

Unfortunately this gif doesn't play audio :) check the sample app to hear it.

Update from 1.0.0 to 1.0.1

Change the package repository to jitpack as explained in next section.

Include

Include the Gradle dependency from jitpack

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

    dependencies {
        ...
        compile 'com.github.HugoMatilla:AudioPlayerView:v1.0.1'
    }

Permissions

AudioPlayerView adds automatically the android.permission.INTERNET permission.

Use

Add the view to your xml.

    <com.hugomatilla.audioplayerview.AudioPlayerView
                android:id="@+id/player"
                ...
    />

Use it in your Activity, Fragment or Custom View

    
    String url = "url-to-your-mp3-file.mp3"
    AudioPlayerView audioPlayerView = (AudioPlayerView) findViewById(R.id.player);
    audioPlayerView.withUrl(url);

Callbacks

There are 3 callbacks:

onAudioPreparing: while the file is being downloaded. Use it if you want to show a progress dialog.

onAudioReady: when the file has finished to be downloaded and is about to start playing. You can use it to hide the progress dialog.

onAudioFinished: When the audio has finished playing and is stopped.

    
    audioPlayerView.setOnAudioPlayerViewListener(new AudioPlayerView.OnAudioPlayerViewListener() {
            @Override
            public void onAudioPreparing() {
                spinner.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAudioReady() {
                spinner.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAudioFinished() {

            }
        });

UI

You can use icons or texts to show the current state of the view: loading, playing or stopped.

The AudioPlayerView extends TextView, so you can do all of the things you would do in a TextView with some considerations.

Icons

For the icons, AudioPlayerView uses icon fonts. When the audio is ready and playing it shows a stop icon, when is finished or it was never started it shows a play button and when is preparing it shows a spinner (spinning).

The spinner icon makes the whole textView spin, so if it has a background color and it is not a round shape you probably won't get what you expected (the icon to spin) but you will see the whole rectagle spinning. In the sample application you can see how to do it.

Text

If you prefer to use text, add the texts to the xml file, and app:useIcons="false".

    <com.hugomatilla.audioplayerview.AudioPlayerView
        ...
        app:loadingText="loading..."
        app:playText="play"
        app:stopText="stop"
        app:useIcons="false"
    />

Custom Icons

You can use your own icon fonts.

    <com.hugomatilla.audioplayerview.lib.AudioPlayerView
        ...
        app:loadingText="@string/customLoadingIcon"
        app:playText="@string/customPlayIcon"
        app:stopText="@string/customStopIcon"
        app:useIcons="true"
    />

You can create your own icon fonts with fontello.com

API

The only public method to manage the audio playback is toggleAudio()

It plays the audio if it is stopped or it was never started (previous load), and it stops the audio if it is playing.

Destroy

Dont forget to destroy the AudioPlayerView when you don't need it anymore. The onDestroy() method of the activity is a good place to have it.

    @Override
    protected void onDestroy() {
        audioPlayerView.destroy();
        super.onDestroy();
    }

License

The MIT License (MIT)

Copyright (c) 2016 Hugo Matilla

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.

You might also like...
đź“„The reliable, generic, fast and flexible logging framework for Android
đź“„The reliable, generic, fast and flexible logging framework for Android

logback-android v2.0.0 Overview logback-android brings the power of logback to Android. This library provides a highly configurable logging framework

A plug and play ;) android library for displaying a
A plug and play ;) android library for displaying a "rate this app" dialog

Easy Rating Dialog This lib provides a simple way to display an alert dialog for rating app. Default conditions to show: User opened the app more than

transai is a localization tool on Android and iOS.

transai transai is a command line tool to help you do Android and iOS translation management. You can extract string files to csv format, or generate

Common rules and macros for Grab's Android projects built with Bazel.

Common rules and macros for Grab's Android projects built with Bazel. This repo provides rules and macros to support some of Android Gradle Plugin features in Bazel.

Purpose for this base architectural project is to load it with all latest components and libraries So it become reference for all kind of Android projects

The purpose of this base architectural project is to load it with all the latest components and libraries, So it becomes a reference for all kinds of Android projects

This was developed with Android studio and firebase Realtime database
This was developed with Android studio and firebase Realtime database

This was developed with Android studio and firebase Realtime database. In this application users are able to see their old result list semester wise. Also they able to pass get analyze about all subject in university. User can predict the GPA value by adding future semester subjects and expected results. Java was used for backend development and XML used for frontend development.

The QuickJS embeddable Javascript engine packaged for Android and the JVM

The QuickJS embeddable Javascript engine packaged for Android and the JVM

Android development recommendation for outdated libraries and current libraries preferred as of 2021

GADS21-Android-Recomendation-For currently used libraries and dependencies Android development recommendation for outdated libraries and current libra

Tutorial For openJDK 11 and AGP 7.0.0+ | Tutorial Multi Library Android in 1 Project | Groovy
Tutorial For openJDK 11 and AGP 7.0.0+ | Tutorial Multi Library Android in 1 Project | Groovy

jitpack-library-guide For openJDK 11 and AGP 7.0.0 + Please read every single note for detail Tutorial Click Here Kotlin DSL Click Here Repository for

Comments
  • play another song in load or play song

    play another song in load or play song

    hi tnx for your library i create one editText and i want audioPlayer play every thing on edittext if i click on audio player .. but i click on it ... continue the dog and do not play new song url in edit text ....

    please add some thing like ClearCache for play another url

    tanks

    opened by alirezanazari 3
  • RecyclerView

    RecyclerView

    this pull request to solve bug when using AudioPlayerView inside RecyclerView

    and inside the RecyclerView Adapter: @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { ... holder.audioPlayerView.destroy(); }

    opened by anasanasanas 2
  • Audio progress bar

    Audio progress bar

    Hello, First of all, thanks for this great library. Simple, beautiful and easy to use. I'd like to know if this lib have some kind of a ProgressBar or SeekBar for the audio? Thanks.

    opened by filpgame 2
  • Multiple songs are played at a same time in RecyclerView

    Multiple songs are played at a same time in RecyclerView

    I am playing audio in RecyclerView. Suppose one song in recyclerview is playing and if you clicked on other recyclerview item (song) then first song should be stopped, but both songs are playing. Please help me to resolve this issue.

    opened by ervinod 0
Releases(v1.0.1)
Owner
Hugo Matilla
Hi 🙋‍♂️
Hugo Matilla
A curated list of standards, tests and benchmarks that can be used for testing and evaluating dev-tools

A curated list of standards, tests and benchmarks that can be used for testing and evaluating dev tools Contribution Add the description of the benchm

null 13 Dec 16, 2022
A customized video view that will automatically pause video is user is not looking at device screen!!!!!

UserAwareVideoView Featured in: Medium What is this library for? UserAwareVideoView is a customizable VideoView that smartly play and pause the video

Keval Patel 51 Jun 27, 2021
A special view that can contain other views (called children)

A ViewGroup is a special view that can contain other views (called children.) The view group is the base class for layouts and views containers. There

Phạm Thành Trung 1 Oct 16, 2021
Create a simple one screen application with scrollable table view

Create a simple one screen application with scrollable table view

Nikola Crnogorac 0 Jan 2, 2023
****. Use the native and support library variants instead - https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html. An android library that makes it easy to add custom fonts to edittexts and textviews

Add to your project Add this line to your dependencies in build.gradle compile 'in.workarounds.typography:typography:0.0.8' Using the views There are

Workarounds 43 Nov 6, 2021
SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device.

#Scripting Layer for Android (SL4A) SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreter

Damon Kohler 2.3k Dec 23, 2022
An application for runners and cyclists. Allows you to monitor your physical activity, weight and receive reminders about workouts.

An application for runners and cyclists. Allows you to monitor your physical activity, weight and receive reminders about workouts.

Just_Amalll 3 Feb 7, 2022
A gradle plugin for getting java lambda support in java 6, 7 and android

Gradle Retrolambda Plugin This plugin will automatically build your java or android project with retrolambda, giving you lambda goodness on java 6 or

Evan Tatarka 5.3k Jan 5, 2023
A Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.

Development in this repository is stopped. Future development continues on https://github.com/yigit/android-priority-jobqueue ========================

Path Mobile Inc Pte. Ltd. 2.4k Dec 9, 2022
An android library for displaying fps from the choreographer and percentage of time with two or more frames dropped

DEPRECATED TinyDancer is deprecated. No more development will be taking place. Check out the Google Android developer documentation for UI performance

Friendly Robot 1.9k Jan 3, 2023