jeancsanchez / jcplayer Goto Github PK
View Code? Open in Web Editor NEW:musical_note: A simple audio player for Android applications.
License: Apache License 2.0
:musical_note: A simple audio player for Android applications.
License: Apache License 2.0
com.example.jean.jcplayer.JcPlayerService.seekTo(JcPlayerService.java:192) at com.example.jean.jcplayer.JcAudioPlayer.seekTo(JcAudioPlayer.java:166) at com.example.jean.jcplayer.JcPlayerView.onProgressChanged(JcPlayerView.java:403) at android.widget.SeekBar.onProgressRefresh(SeekBar.java:91) at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:660) at android.widget.ProgressBar.refreshProgress(ProgressBar.java:672) at android.widget.ProgressBar.setProgress(ProgressBar.java:719) at android.widget.AbsSeekBar.trackTouchEvent(AbsSeekBar.java:451) at android.widget.AbsSeekBar.onTouchEvent(AbsSeekBar.java:372) at android.view.View.dispatchTouchEvent(View.java:7713) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2329) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1568)
When i try to add compile 'io.github.jeancsanchez.jcplayer:jcplayer:0.0.2' it gives the following error
Manifest merger failed : Attribute application@icon value=(@mipmap/ic_launcher_round) from AndroidManifest.xml:14:9-49 is also present at [io.github.jeancsanchez.jcplayer:jcplayer:0.0.2] AndroidManifest.xml:14:9-43 value=(@mipmap/ic_launcher). Suggestion: add 'tools:replace="android:icon"' to element at AndroidManifest.xml:11:5-65:19 to override.
How to pause/stop player programmatically?
1- TextView (txt_current_music_notification) marquee not working.
2- When I touch the pause button in the Player, the Pause icon on the Notification does not change to Play.
Hello is there any callback for the list view ? like on long press click on the list ? thank you.
I can't use multiple jcAudioPlayer in RecyclerView.
Click events repeat
Hello,
Thank you for the wonderful Project at least its not complicated as the others.. just the project i needed,
i have a problem when i add the dependency to my android gradle it fails to resolve, thank you
i'm using:
compile 'io.github.jeancsanchez.jcplayer:jcplayer:2.0.3-alpha'
Hey there guys, I want to play audio files from the internet using jcplayer. I know it is possible with the function createFromURL() can anyone tell me how do I cache the song played from url and store it on the apps private cache, so that later I can retrieve it from the cache without internet connectivity.
This could be really useful to me to allow users to play songs without internet, once they have played/downloaded the song once when the are connected, later they can play without internet,
I've test the code, it's working with removing the audio.
There is one question:
if we removing the current played audio, the player will still play the audio. From my perspective, player should play the next audio. But if the audio is the only audio in the playlist, player should stop itself. How do we address the problem?
While changing the position of seekbar and when it comes near the play/pause button it touches and the song get paused!
Is that only ACCESS NETWORK STATE and INTERNET?
I love your application and would want to contribute to it, I'm not a developer but I am good at copywriting. I would love to make a copywrite for your Readme and make a pull request for you to merge. Your response would be highly appreciated. Also I would like to request if we could communicate either here or via email, so I don't have to create issues. Thank you.
I've tinkering with JcPlayer and success in implementing feature for raw, assets, and file path for the audio file. I'm using a pojo for categorizing each files based on its source. The pojo is like this:
public class FileAndOrigin {
private String filePath;
private Origin origin;
...
// getter, setter, and constructor omitted.
}
where the Origin is an enum:
public enum Origin {
URL, RAW, ASSETS, FILE_PATH
}
So, if we want to add the file we only need to do this:
ArrayList<FileAndOrigin> urls = new ArrayList<>();
urls.add(new FileAndOrigin("http://www.villopim.com.br/android/Music_01.mp3", Origin.URL));
urls.add(new FileAndOrigin("http://www.villopim.com.br/android/Music_02.mp3", Origin.URL));
urls.add(new FileAndOrigin(this.getFilesDir() + "/" + "13.mid", Origin.FILE_PATH));
urls.add(new FileAndOrigin("49.v4.mid", Origin.ASSET));
urls.add(new FileAndOrigin("56.mid", Origin.ASSET));
urls.add(new FileAndOrigin(String.valueOf(R.raw.a_203), Origin.RAW));
urls.add(new FileAndOrigin(String.valueOf(R.raw.a_34), Origin.RAW));
player.initWithPlaylist(urls, "Awesome music");
And in JcPlayerService, we only need to do a slight changes in play
method (this is a rough change):
public void play(JcAudio jcAudio) {
this.currentJcAudio = jcAudio;
try {
if (mediaPlayer == null) {
mediaPlayer = new MediaPlayer();
if(jcAudio.getOrigin() == Origin.URL) {
mediaPlayer.setDataSource(jcAudio.getUrl());
} else if(jcAudio.getOrigin() == Origin.RAW) {
AssetFileDescriptor afd = getApplicationContext().getResources().openRawResourceFd(Integer.parseInt(jcAudio.getUrl()));
if (afd == null) return; // TODO: Should throw error.
mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
} else if(jcAudio.getOrigin() == Origin.ASSET) {
AssetFileDescriptor afd = getApplicationContext().getAssets().openFd(jcAudio.getUrl());
mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
} else if(jcAudio.getOrigin() == Origin.FILE_PATH) {
Log.d(TAG, "file://"+jcAudio.getUrl());
mediaPlayer.setDataSource(getApplicationContext(), Uri.parse(jcAudio.getUrl()));
}
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setOnBufferingUpdateListener(this);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setOnErrorListener(this);
} else if (isPlaying) {
stop();
play(jcAudio);
} else {
mediaPlayer.start();
isPlaying = true;
if(jcPlayerServiceListener != null)
jcPlayerServiceListener.onContinueAudio();
}
}catch (IOException e){
e.printStackTrace();
}
updateTimeAudio();
jcPlayerServiceListener.onPlaying();
if(notificationListener != null)
notificationListener.onPlaying();
}
This is working currently.
But, Is it a good design for JcPlayer?
How to hide the forward and backward buttons in the UI ??
It would be nice if the player also had two buttons for fast forward and back , that will set the current track a few seconds forward or backward
Getting
E/MediaPlayer: Should have subtitle controller already set
and
AudioFeedActivity has leaked ServiceConnection com.example.jean.jcplayer.JcAudioPlayer$1@422d1740 that was originally bound here
while exiting from the app
I didn't see any docs about just using files...so does your library accept local audio files?
I am creating notification in onStop but when user killed the app, notification still exist and causes a crash if you click it. is it possible to remove notification when app is killed?
@Override
protected void onStop() {
super.onStop();
// Create notification
jcplayerView.createNotification();
}
@Override
protected void onDestroy() {
super.onDestroy();
// Destroy notification
}
Can add a custom icon for each player buttons is a nice feature.
How can I set an audio in loop?
hello thanks for this cool music player
i really cant add it to dependencies
compile 'io.github.jeancsanchez.jcplayer:jcplayer:{version}'
when i set 0.0.2 instead of {version} it fails
and the same when i set it to 3.3
please create another new simple project with clear dependencies
Adding the custom JcPlayerView to my project throws a nullpointerexception as it cannot inflate UI component. Here is the error.
Exception Details java.lang.NullPointerException at com.example.jean.jcplayer.JcPlayerView.init(JcPlayerView.java:69) at com.example.jean.jcplayer.JcPlayerView.(JcPlayerView.java:50) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:835) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
...
Here is how I added the UI component:
<com.example.jean.jcplayer.JcPlayerView
android:id="@+id/reminder_media_player"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
When I kill the app it should clear the notification unfortunately does not; the app destroyed but the notification still shown, when I click one of its buttons (previous, pause/play or next) the app raises an NullExceptionError on jcPlayerNotificationReceiver.java
here
Info:
-I test it on Android 7.0
-App's configuration still as its in this library (not changed).
Any suggestion that can help fix the issue!
Right now, the library does not support local file storage. This, of course, should be a thing that is essential to such a library. Are there any plans on supporting this?
Is there any way to override the URL checker?
is there a way to have OnNextClick() event ?
if you can add a random button,that will be nice.
and notification is deleted after the app is killed by the device.
Thank you it was a great job (y)
I try to click previous button before play and then i got a force close
java.lang.NullPointerException: Attempt to invoke virtual method 'long com.example.jean.jcplayer.JcAudio.getId()' on a null object reference
at com.example.jean.jcplayer.JcAudioPlayer.updatePositionAudioList(JcAudioPlayer.java:197)
at com.example.jean.jcplayer.JcAudioPlayer.previousAudio(JcAudioPlayer.java:154)
at com.example.jean.jcplayer.JcPlayerView.previous(JcPlayerView.java:403)
at com.example.jean.jcplayer.JcPlayerView.onClick(JcPlayerView.java:436)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22277)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:159)
at android.app.ActivityThread.main(ActivityThread.java:6097)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Hi @jeancsanchez ,
Thanks for the sharing, how can i get the call back of each audio is played. I tried the sample application unfortunately i can't able get completion listener or info listener like a behavior. Can you please share us to add. Thanks.
I am using
compile 'io.github.jeancsanchez.jcplayer:jcplayer:0.0.2'
but even though my project detects Jcplayer, JcPlayerView,JcPlayer service it does not detects JCAudio Jcservice etc.
this player not stop evry. loop play track?
I have been trying out the sample app and checking it out and trying to help as much as I can,
I have a question @jeancsanchez What does the updateProgress() function in line 98 inside the AudioAdapater class do in the Sample App?
for Your Reference I have pasted the function below:
public void updateProgress(JcAudio jcAudio, float progress) {
int position = jcAudioList.indexOf(jcAudio);
Log.d(TAG, "Progress = " + progress);
progressMap.put(position, progress);
if(progressMap.size() > 1) {
for(int i = 0; i < progressMap.size(); i++) {
if(progressMap.keyAt(i) != position) {
Log.d(TAG, "KeyAt(" + i + ") = " + progressMap.keyAt(i));
notifyItemChanged(progressMap.keyAt(i));
progressMap.delete(progressMap.keyAt(i));
}
}
}
notifyItemChanged(position);
}
Hi , i have some issue here , in 5.0 and above versions its not working.... it just loading ...finally getting not responding ...please give a solution
Thanks in advance
Can you add soundpool to play simple sounds gapless to JcPlayer2. Mediaplayer class make gap in looping
When I use this jcplayerView.createNotification(R.drawable.myIcon); // Your icon resource
I only see a square with any icon, are there any restriction in the drawable??
Hello,
I am testing your library with a simple code
JcPlayerView jcplayerView = (JcPlayerView) findViewById(R.id.jcplayer);
ArrayList<JcAudio> jcAudios = new ArrayList<>();
jcAudios.add(JcAudio.createFromFilePath("Asset audio", "/sdcard/Download/"+audioname));
jcplayerView.initPlaylist(jcAudios);
jcplayerView.playAudio(jcplayerView.getMyPlaylist().get(0));
And if I comment out the last line, a player shows in the activity and works awesome. However if i leave the line uncommented I get Attempt to invoke virtual method 'void com.example.jean.jcplayer.JcPlayerService.play(com.example.jean.jcplayer.JcAudio)' on a null object reference. The object I am referencing is not null, I checked that. What I am trying to do here is to autoplay the audio. Any idea why this is so? I am writing here as it seems to be a bug.
BTW, love the library.
Very best regards.
thank you for this
but could you plz update the dependency version and instead of {version} write number version
now i dont know what is the version so could you help me ?
First Problem : it just show the control (backward,forward,pause,duration and title)
There no music list like in your picture (awesome music 1, awesome music 2) based in my code, this should add "Another One Bities Of Dust","Be Starters","Gee,"Crazy Frogs" etc to the music list and show it right?
Second Problem: the music is played properly, but when i keep forward the audio, it just play till "Feel This Moment" 6 more audio are not added to the playlist, but in code , i added it, why?
My apk : https://ufile.io/0ycnh sorry if i upload here
code :
player = (JcPlayerView)findViewById(R.id.musicplayer);
ArrayList musicList = new ArrayList();
musicList.add(JcAudio.createFromURL("Another One Bities Of Dust","https://s1.vocaroo.com/media/download_temp/Vocaroo_s1zqcwflJjFT.mp3"));
musicList.add(JcAudio.createFromURL("Be Starters","https://s1.vocaroo.com/media/download_temp/Vocaroo_s1KMVtNBwtGW.mp3"));
musicList.add(JcAudio.createFromURL("Crazy Frogs","https://s1.vocaroo.com/media/download_temp/Vocaroo_s1IN5m15oEcu.mp3"));
musicList.add(JcAudio.createFromURL("Dance Of The Knights","https://s1.vocaroo.com/media/download_temp/Vocaroo_s1UtUmVB1Tl2.mp3"));
musicList.add(JcAudio.createFromURL("Dumags","https://s1.vocaroo.com/media/download_temp/Vocaroo_s1CcypsYOiS7.mp3"));
musicList.add(JcAudio.createFromURL("Feel This Moment","https://s1.vocaroo.com/media/download_temp/Vocaroo_s1AfxoRr8dk3.mp3"));
musicList.add(JcAudio.createFromURL("Flight Of The Bumblebee","https://s1.vocaroo.com/media/download_temp/Vocaroo_s15cjibddJl2.mp3"));
musicList.add(JcAudio.createFromURL("Game of Thrones","https://s1.vocaroo.com/media/download_temp/Vocaroo_s1srPoxtfSeA.mp3"));
musicList.add(JcAudio.createFromURL("Gee","https://s1.vocaroo.com/media/download_temp/Vocaroo_s14Lx19MsFxa.mp3"));
musicList.add(JcAudio.createFromURL("Growtopia Menu","https://s1.vocaroo.com/media/download_temp/Vocaroo_s1RU8xv4uosK.mp3"));
musicList.add(JcAudio.createFromURL("Here With You","https://s1.vocaroo.com/media/download_temp/Vocaroo_s1R52lycmdAp.mp3"));
musicList.add(JcAudio.createFromURL("Hey There Darlin","https://s1.vocaroo.com/media/download_temp/Vocaroo_s1qZzHc11Ybl.mp3"));
musicList.add(JcAudio.createFromURL("I Need Your Love","https://s1.vocaroo.com/media/download_temp/Vocaroo_s1AJ93YXmOnN.mp3"));
player.initWithTitlePlaylist(musicList,"Growtopia Music");
Like title says , in the demo app and readme only mentions Activity, will it work with Fragments?
Working perfectly, but I am not getting any notification while playing audio.
`jcplayerView = (JcPlayerView) findViewById(R.id.jcplayer);
String mp3 = getIntent().getStringExtra("content");
String mp3_title = getIntent().getStringExtra("title");
jcplayerView.createNotification(); // default icon
ArrayList<JcAudio> jcAudios = new ArrayList<>();
jcAudios.add(JcAudio.createFromURL(mp3_title, mp3));
jcplayerView.initPlaylist(jcAudios);`
jcplayerView = (JcPlayerView) findViewById(R.id.singlepost_player);
ArrayList<JcAudio> jcAudios = new ArrayList<>();
jcAudios.add(JcAudio.createFromURL("url audio","https://firebasestorage.googleapis.com/v0/b/musyc-f264f.appspot.com/o/Karone-Okarone-Minar-Rahman-Official-Music-Video-Eagle-Music.mp3?alt=media&token=a40ed28a-2970-4160-ac1d-33881e34253a"));
jcplayerView.initPlaylist(jcAudios);
How can I paused Audio from BroadcastReceiver when I having an income call and continue it when call is end? Thank you!
12-27 17:11:56.020 E/AndroidRuntime(24331): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.animation.AnimatorCompatHelper" on path: DexPathList[[zip file "/data/app/org.redeagle.gtmusic-1/base.apk"],nativeLibraryDirectories=[/data/app/org.redeagle.gtmusic-1/lib/arm64, /system/lib64, /vendor/lib64]]
W/System.err: java.lang.IndexOutOfBoundsException: Index: 9, Size: 9
W/System.err: at java.util.ArrayList.get(ArrayList.java:411)
W/System.err: at com.example.jean.jcplayer.JcAudioPlayer.nextAudio(JcAudioPlayer.java:95)
W/System.err: at com.example.jean.jcplayer.JcPlayerView.next(JcPlayerView.java:161)
W/System.err: at com.example.jean.jcplayer.JcPlayerView.onClick(JcPlayerView.java:213)
W/System.err: at android.view.View.performClick(View.java:5637)
W/System.err: at android.view.View$PerformClick.run(View.java:22429)
W/System.err: at android.os.Handler.handleCallback(Handler.java:751)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err: at android.os.Looper.loop(Looper.java:154)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6119)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
It looks like that file names have the different register than class names:
/private/var/folders/3k/mymj0cx15f9c3m0kv4gch66h0000gn/T/1479061516586-0/src/JcPlayer-master/jcplayer/src/main/java/com/example/jean/jcplayer/JCAudio.java:9: error: class JcAudio is public, should be declared in a file named JcAudio.java
public class JcAudio implements Serializable {
^
/private/var/folders/3k/mymj0cx15f9c3m0kv4gch66h0000gn/T/1479061516586-0/src/JcPlayer-master/jcplayer/src/main/java/com/example/jean/jcplayer/JCAudioPlayer.java:18: error: class JcAudioPlayer is public, should be declared in a file named JcAudioPlayer.java
public class JcAudioPlayer {
^
/private/var/folders/3k/mymj0cx15f9c3m0kv4gch66h0000gn/T/1479061516586-0/src/JcPlayer-master/jcplayer/src/main/java/com/example/jean/jcplayer/JCNotificationPlayer.java:16: error: class JcNotificationPlayer is public, should be declared in a file named JcNotificationPlayer.java
public class JcNotificationPlayer implements JcPlayerService.JCPlayerServiceListener{
^
/private/var/folders/3k/mymj0cx15f9c3m0kv4gch66h0000gn/T/1479061516586-0/src/JcPlayer-master/jcplayer/src/main/java/com/example/jean/jcplayer/JCPlayerNotificationReceiver.java:9: error: class JcPlayerNotificationReceiver is public, should be declared in a file named JcPlayerNotificationReceiver.java
public class JcPlayerNotificationReceiver extends BroadcastReceiver {
^
/private/var/folders/3k/mymj0cx15f9c3m0kv4gch66h0000gn/T/1479061516586-0/src/JcPlayer-master/jcplayer/src/main/java/com/example/jean/jcplayer/JCPlayerService.java:12: error: class JcPlayerService is public, should be declared in a file named JcPlayerService.java
public class JcPlayerService extends Service implements
^
/private/var/folders/3k/mymj0cx15f9c3m0kv4gch66h0000gn/T/1479061516586-0/src/JcPlayer-master/jcplayer/src/main/java/com/example/jean/jcplayer/JCPlayerView.java:23: error: class JcPlayerView is public, should be declared in a file named JcPlayerView.java
public class JcPlayerView extends LinearLayout implements
I want to get current time as 00:00:00 ( hours, minutes, seconds) How can I do it?
you may support to play files from assets and raw folders as well
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.