android-mediaplayer

How to play a sound simultaneously using SoundPool for a specific period of time

纵饮孤独 提交于 2019-12-25 01:45:15
问题 I am working with an android media application for that i want play a sound file simultaneously for a specific period of time. So i've created a Class and i am using SoundPool and Thread concepts inside this class to play the sound but when i run my application it is going to an ANR state and showing a warning in log-cat sample 2130968576 not READY anyone please help me to fix this... Class package com.kodspider.funk; import android.content.Context; import android.media.AudioManager; import

MediaPlayer - setAudioAttributes not working properly

北城余情 提交于 2019-12-24 20:52:41
问题 I'm trying to create an alarm, everything is working fine but the stream type is always media even tho I use STREAM_ALARM , since setStreamType is deprecated, I'm using setAudioAttributes instead but it doesn't seem to work. here's my code : class AlarmRingtoneManager(val context: Context) { private lateinit var mediaPlayer: MediaPlayer fun start() { mediaPlayer = MediaPlayer.create(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)) .apply { setAudioAttributes(AudioAttributes

Binding MediaPlayer to be played at a specific time

旧巷老猫 提交于 2019-12-24 19:25:54
问题 When using MediaPlayer, I noticed that whenever my phone stucks, the MediaPlayer glitches and then continues playing from the position in the audio it glitched. This is bad for my implementation since I want the audio to be played at a specific time. If I have a song of 1000 millisecond length, I want is the ability to set MediaPlayer to start playing at some specific time t , and then exactly stop at at time t+1000 . This means that I actually need two things: 1) Start MediaPlayer at a

No “number_of_albums column” in MediaStore.Audio.Artists

我的梦境 提交于 2019-12-24 17:00:58
问题 I want to retrieve data from MediaStore especially the number of albums per artist but SQLite throws me an exception no such column: number_of_albums (code 1): while compiling: SELECT artist_key, artist, number_of_albums FROM audio WHERE (is_music != 0) Can someone explain me what I am doing wrong? My code : private List<Artist> getArtistList() { String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"; String[] projection = { MediaStore.Audio.Artists.ARTIST_KEY, MediaStore.Audio.Artists

Android Music Player Service not playing after home/back button is pressed

二次信任 提交于 2019-12-24 14:03:48
问题 Am trying to write music player code in android.I wrote the MediaPlayer code in a service.Here is the code: package com.example.audioservice; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.os.IBinder; import android.util.Log; public class MyService extends Service { static MediaPlayer mp; @Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); System.out.println("in MyService onCreate()"); mp

Any clues about MediaPlayer Info/Warning 950?

久未见 提交于 2019-12-24 11:33:43
问题 I've been playing some mp4 videos through the VideoView, which apparently uses/is a wrapper for the MediaPlayer. As usual I see the typical ones in the logcat: I/MediaPlayer﹕ Info (701,0) I/MediaPlayer﹕ Info (702,0) But then I see that one as well: I/MediaPlayer﹕ Info (950,0) As stated in this answer and others questions, most 9XX MediaPlayer Info/Warning/Error codes aren't officially documented in the SDK docs, but probably is related with "timed text tracks" (subtitles), since the only

Android make my app files only play from inside the app

為{幸葍}努か 提交于 2019-12-24 11:07:40
问题 I created an app in which the client can record few conversations and store in external storage. The client must be able to transfer the files if needed. So I am storing the recorded files in external storage. But client don't want the files to be played from outside the app, (from sd card) or from music player. Is it possible? Please let me know. Is using internal storage is the only way to do it? 回答1: well this is not a programming question, but ... you have 2 options here, decide based on

Android: Playing two sounds one after the other

一笑奈何 提交于 2019-12-24 08:24:04
问题 I am trying to play two sound items, one after the other MediaPlayer mp = null; protected void produceErrorSound(int index) { if (mp != null) { mp.reset(); mp.release(); } mp = MediaPlayer.create(this, index); mp.start(); } public void correctAnswerAndNext(){ produceErrorSound(R.raw.right1) ; produceErrorSound(R.raw.right1) ; } but only second sound is produced. is there any alternative approach? 回答1: I can't see any wait mechanism in your code. You can use an onCompletionListener to receive

While playing sound using media player in loop there is some pause in the loop which is annoying for our user

大城市里の小女人 提交于 2019-12-24 07:25:35
问题 We are playing the small audio clip in infinity loop using MediaPlayer in android but there is very small around (200 ms) pause between a loop in the sound which is very annoying because of its break continuity of sound. MediaPlayer mp = new MediaPlayer(); try { AssetFileDescriptor descriptor = getAssets().openFd(file); mp.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength()); descriptor.close(); mp.prepare(); mp.setLooping(true); mp.start(); }

Android mediaplayer singleton service won't stop playing

风格不统一 提交于 2019-12-24 06:58:10
问题 I need to have background music in all my activities. It should stop when the application is not foreground. As I'm developing for 2.3 I can't use the ActivityLifeCycleCallBacks class. I implemented the solution at Checking if an Android application is running in the background and then decided to make the mediaplayer a singleton and use it in a service. Everything works fine and if I press home, select quit from the menu or I make the application go background any way the sound stops but...