media-player

Can I use Basic HTTP Authentication with Android MediaPlayer?

穿精又带淫゛_ 提交于 2019-12-02 03:58:35
I cant find a way to use an url that requires basic auth when im useing mp.setDataSource(url); MediaPlayer mp = new MediaPlayer(); mp.setDataSource(url); mp.prepareAsync(); Anyone that got any ideas? This worked for me: public void setupMediaPlayer(){ // Setup Media Player and Prepare to Play media = new MediaPlayer(); media.setAudioStreamType(AudioManager.STREAM_MUSIC); // Authdata String username = "username"; String password = "password"; // encrypt Authdata byte[] toEncrypt = (username + ":" + password).getBytes(); String encoded = Base64.encodeToString(toEncrypt, Base64.DEFAULT); //

how to know when audio is started playing in android

拥有回忆 提交于 2019-12-02 00:27:17
问题 In my application I want to get start time of music player when user started and end time when it stops.I don't want to start any music player in my app. I just want to track user activity in device. So i want my application to get any notification when user started the music . Do I get any intent for music player started and it stopped.Or do I get any intent for when user opens music files. Is there any other method other than intent to capture the start time and and time when user starts

how to know when audio is started playing in android

痞子三分冷 提交于 2019-12-01 21:24:36
In my application I want to get start time of music player when user started and end time when it stops.I don't want to start any music player in my app. I just want to track user activity in device. So i want my application to get any notification when user started the music . Do I get any intent for music player started and it stopped.Or do I get any intent for when user opens music files. Is there any other method other than intent to capture the start time and and time when user starts music player. Well you can implement the interface 'AudioManager.OnAudioFocusChangeListener' in which

How do I loop my Media Player files?

自闭症网瘾萝莉.ら 提交于 2019-12-01 19:38:40
Basically I have 3 songs, and I want the user to be able to loop back to the first song once the cycle of 3 songs is complete. Why won't this work? It will play all 3 songs, then on the fourth click, no song is played. MediaPlayer song0, song1, song2; Button play, next; ArrayList<MediaPlayer> music = new ArrayList<MediaPlayer>(); int track = 0; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); song0 = MediaPlayer.create(TheParty0Activity.this, R.raw.blacksunempire);

How do I loop my Media Player files?

偶尔善良 提交于 2019-12-01 19:32:01
问题 Basically I have 3 songs, and I want the user to be able to loop back to the first song once the cycle of 3 songs is complete. Why won't this work? It will play all 3 songs, then on the fourth click, no song is played. MediaPlayer song0, song1, song2; Button play, next; ArrayList<MediaPlayer> music = new ArrayList<MediaPlayer>(); int track = 0; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

Android Oreo: Keep started background service alive without setting it foreground (but with a notification)?

穿精又带淫゛_ 提交于 2019-12-01 18:27:26
问题 I am working on a media app. I wonder how I can keep some old behavior my app has prior to Oreo, for example, have the notification and the service (for playback) hang in there even if the service is no longer set to foreground. We call startService(MediaPlaybackService.class) to start the service when playback starts, then create a notification and call startForeground() with it on the service. So far so good - if user exits the app, user will still have media play in the background and can

Android Oreo: Keep started background service alive without setting it foreground (but with a notification)?

☆樱花仙子☆ 提交于 2019-12-01 18:07:14
I am working on a media app. I wonder how I can keep some old behavior my app has prior to Oreo, for example, have the notification and the service (for playback) hang in there even if the service is no longer set to foreground. We call startService(MediaPlaybackService.class) to start the service when playback starts, then create a notification and call startForeground() with it on the service. So far so good - if user exits the app, user will still have media play in the background and can control the playback from the notification. When user pauses playback, we call stopForeground(false) to

Context inside a Runnable

旧时模样 提交于 2019-12-01 17:38:35
问题 I try to play a sound from R.raw. inside a Thread/Runnable But I can't get this to work. new Runnable(){ public void run() { //this is giving me a NullPointerException, because getBaseContext is null MediaPlayer mp = MediaPlayer.create( getBaseContext(), R.raw.soundfile); while (true) { if (something) play something } } How can I get the real Context inside the run method? It is null no matter what I try. Or is there a better way to do this? 回答1: You should also be able to get the this

MediaPlayer setDataSource need best practice advice

大城市里の小女人 提交于 2019-12-01 16:44:54
After reading " Media Playback " and " MediaPlayer " android documentations I'm still confused and need experienced advice about setDataSource overloaded method. I am using MediaPlayer in a Service component in my Project that is going to be a foregroundService while playing music. I have my music file(.mp3) in res/raw folder of my apk. To start playing, I know I have to prepare the MediaPlayer object. Because Services in android applications by default uses single process and main thread, I don't want my users get ANR while MediaPlayer prepares itself(think if media file in raw folder has a

Android MediaPlayer prepare failed: status = 0x1

北战南征 提交于 2019-12-01 16:02:15
I'm building an audio recorder that needs to play back the recorded sound. I'm running into a lot of trouble playing back the audio. I know that the file exists because I isolated it into a folder on my SD Card, but for some reason it can't play it back. Here is my code: public class RecorderEditActivity extends SherlockActivity implements DatabaseHelper.MetadataListener { private long position; private Button playButton = null; private TextView date = null; private EditText title = null; private EditText notes = null; private Button saveButton = null; private MediaPlayer mediaPlayer = null;