android-music-player

Mediaplayer stream online MP3 file

牧云@^-^@ 提交于 2019-11-28 00:17:32
问题 I have an Android app that streams an MP3 file and plays this file in player, but the problem is mediaPlayer.prepare(); takes a long time buffering and the app freezes so I tried to use prepareAsync(); , but with this function I can't make the player play the next file. It just plays a single file online; if I need to play another file I have to close and restart the activity when play ends. This is my code: public void playMp3(String _link) { mediaPlayer.setOnPreparedListener(new

Not able to get getDuration() for AAC file using ExoPlayer

你说的曾经没有我的故事 提交于 2019-11-27 16:30:59
I have been trying to stream a URL using ExoPlayer . The URLs: STREAM_URL_1 = " http://storage.googleapis.com/exoplayer-test-media-0/play.mp3 " STREAM_URL_2 = " https://s3-ap-southeast-1.amazonaws.com/ok.talk.channels/zakirkhan/Zakir+khan+-+when+my+father+took+my+gf%27s+call.aac " Both URLs play but I am not able to get the getDuration() for STREAM_URL_2 which is an .aac file. The .mp3 works. The following is how I do it. How do I get the getDuration() for the 2nd URL. Even seekTo() doesn't work if getDuration() doesn't work. What change should I make? Do I need to change any Extractor ?

How to turn the volume to max programmatically on android? [duplicate]

与世无争的帅哥 提交于 2019-11-27 13:05:23
This question already has an answer here: How to control volume in android? 1 answer I am writing an app for android that turns up the volume and plays a song for 45 seconds and then stops. That works great, however I can only get the volume to turn up to 50%, Is there a way to turn the volume up to 100% using setVolume()? This is my code: final MediaPlayer mp = MediaPlayer.create(context, R.raw.sound_file_1); //plays eye of the tiger for 45 seconds if (messages.contains("MUSIC ONLY")){ //turn up the volume mp.setVolume(20, 20); mp.start(); //play ring tone for 45 seconds new Timer().schedule

Android - MediaPlayer Buffer Size in ICS 4.0

北城余情 提交于 2019-11-27 09:36:23
问题 I'm using a socket as a proxy to the MediaPlayer so I can download and decrypt mp3 audio before writing it to the socket. This is similar to the example shown in the NPR news app however I'm using this for all Android version 2.1 - 4 atm. NPR StreamProxy code - http://code.google.com/p/npr-android-app/source/browse/Npr/src/org/npr/android/news/StreamProxy.java My issue is that playback is fast for 2.1 - 2.3, but in Android 4.0 ICS the MediaPlayer buffers too much data before firing the

How do you check if music is playing by using a broadcast receiver?

﹥>﹥吖頭↗ 提交于 2019-11-27 04:07:34
I would like to prevent some of my code from executing only when music or videos are currently playing. How would I accomplish this using a broadcast receiver? You don't need a broadcast receiver for this - AudioManager is your friend: AudioManager.isMusicActive() does the job you want, have a closer look here for details: AudioManager here is an example: AudioManager manager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE); if(manager.isMusicActive()) { // do something - or do it not } 来源: https://stackoverflow.com/questions/7323915/how-do-you-check-if-music-is-playing-by-using-a

How to turn the volume to max programmatically on android? [duplicate]

試著忘記壹切 提交于 2019-11-26 16:12:52
问题 This question already has an answer here: How to control volume in android? 1 answer I am writing an app for android that turns up the volume and plays a song for 45 seconds and then stops. That works great, however I can only get the volume to turn up to 50%, Is there a way to turn the volume up to 100% using setVolume()? This is my code: final MediaPlayer mp = MediaPlayer.create(context, R.raw.sound_file_1); //plays eye of the tiger for 45 seconds if (messages.contains("MUSIC ONLY")){ /

How to put media controller button on notification bar?

烂漫一生 提交于 2019-11-26 15:54:24
I am creating a music player application. I want to show the media controller on notification bar while my application is running in background. It looks like Google player. How to do this? Roadies For getting media player controller in your app simply follow this: Call this method in your MainActivity public void showNotification(View view){ new MyNotification(this); finish(); } Create a new MynotificationClass public class MyNotification extends Notification { private Context ctx; private NotificationManager mNotificationManager; @SuppressLint("NewApi") public MyNotification(Context ctx){

How do you check if music is playing by using a broadcast receiver?

人走茶凉 提交于 2019-11-26 12:43:05
问题 I would like to prevent some of my code from executing only when music or videos are currently playing. How would I accomplish this using a broadcast receiver? 回答1: You don't need a broadcast receiver for this - AudioManager is your friend: AudioManager.isMusicActive() does the job you want, have a closer look here for details: AudioManager here is an example: AudioManager manager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE); if(manager.isMusicActive()) { // do something - or

READ_EXTERNAL_STORAGE permission for Android

假如想象 提交于 2019-11-26 12:15:13
I'm trying to access media files (music) on the users device to play them; an easy "hello world"-music player app. I've followed some tutorials and they basically give the same code. But it won't work; it keeps crashing and telling me: error..... Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media from pid=27696, uid=10059 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission() .... Now, this is my manifest file: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android=

How to stop other apps playing music from my current activity?

故事扮演 提交于 2019-11-26 08:19:10
问题 In my app I am trying to make a button which when clicked stops all other apps that are playing music. What I want is similar to that if I am playing music through one music player and if I try playing some other music through a second music player, the current music player stops and then the second one starts. How do we stop other apps playing music from current activity/app? 回答1: AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE); // Request audio focus for playback int