Search Results

Search found 17 results on 1 pages for 'soundpool'.

Page 1/1 | 1 

  • SoundPool.load() and FileDescriptor from file

    - by Hans
    I tried using the load function of the SoundPool that takes a FileDescriptor, because I wanted to be able to set the offset and length. The File is not stored in the Ressources but a file on the storage card. Even though neither the load nor the play function of the SoundPool throw any Exception or print anything to the console, the sound is not played. Using the same code, but use the file path string in the SoundPool constructor works perfectly. This is how I have tried the loading (start equals 0 and length is the length of the file in miliseconds): FileInputStream fileIS = new FileInputStream(new File(mFile)); mStreamID = mSoundPool.load(fileIS.getFD(), start, length, 0); mPlayingStreamID = mSoundPool.play(mStreamID, 1f, 1f, 1, 0, 1f); If I would use this, it works: mStreamID = mSoundPool.load(mFile, 0); mPlayingStreamID = mSoundPool.play(mStreamID, 1f, 1f, 1, 0, 1f); Any ideas anyone? Thanks

    Read the article

  • Soundpool sample not ready

    - by SteD
    I have a .wav file that I'd like to use across my game, currently I am loading the sound in onCreate() of each activity in the game. soundCount = soundpool.load(this,R.raw.count, 1); The sound will be played once the activity starts. soundpool.play(soundCount, 0.9f, 0.9f, 1, -1, 1f); Problem is at times I will hit the error "sample x not ready". Is it possible to load the .wav file once upon starting the game and keep it in memory and use it later across the game? Or is it possible to wait for 1-2 seconds for the sound to load finish?

    Read the article

  • SoundPool repeating issue for Samsung Galaxy S3

    - by Alaa Eldin
    I'm trying to play a background sound for my application, I use SoundPool class, my problem is that, sound plays well only when I set the loop parameter with zero value, but it doesn't work for any other value. My code for initialization is: soundpool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0); soundsMap = new HashMap<Integer, Integer>(); soundsMap.put(1, soundpool.load(this, R.raw.soundfile_1, 1)); soundsMap.put(2, soundpool.load(this, R.raw.soundfile_2, 1)); my code for playing is soundpool.play(1, 0.9f, 0.9f, 1, -1, 1f); as I mentioned sound works when I put (0) instead of (-1) for the loop value, anyone has any idea why (-1) or any value other than (0) doesn't work (there is no output sound) ?

    Read the article

  • Strange resource not found issue?

    - by xBroak
    i seem to be having a very strange problem, when the app is run on my test phone it works perfectly, and plays a sound from the raw folder via soundpool on button press, however when i submit my app to testing after building it it crashes on 120+ devices for 'Resource not found' codes below: Please also note, the file is in fact there, in both the R file, in the compiled APK file and i have also cleaned numerous times. http://www.appthwack.com/public/FUVGFZn42q '01-03 21:09:36.828 26762 26762 W System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{appinventor.ai_Broak.PaintballWiz/com.muo.paintballwiz.PaintballWiz}: android.content.res.Resources$NotFoundException: File res/raw/pballshot.ogg from drawable resource ID #0x7f050000 - 1 occurrence' soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100); //soundPoolMap = new SparseIntArray(); soundPoolMap = new HashMap<Integer, Integer>(); // soundPoolMap.put(soundID, soundPool.load(this, R.raw.midi_sound, 1)); int myAudioFile = getResId("pballshot", R.raw.class); soundPoolMap.put(soundID, soundPool.load(PaintballWiz.this, myAudioFile, 1)); audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); curVolume = audioManager .getStreamVolume(AudioManager.STREAM_MUSIC); maxVolume = audioManager .getStreamMaxVolume(AudioManager.STREAM_MUSIC); leftVolume = curVolume / maxVolume; rightVolume = curVolume / maxVolume; soundPool.play(soundID, leftVolume, rightVolume, priority, no_loop, normal_playback_rate); soundPool.play(soundID, 0, 0, 1, -1, 1f);

    Read the article

  • Android Xperia X10 SoundPool

    - by Gaz
    Hi All, I have had some reports from users of my android app that there is no sound being played on the X10. I'm a bit confused as it works on all other phones that I have tried, Neus One, Hero, Droid. I'm using the SoundPool class to play sounds, has anybody else had similar issues with the X10? Thanks, Gaz

    Read the article

  • Playing Multiple sounds at the same time in Android

    - by Wrapper
    I am unable to use the following to code to play multiple sounds/beeps simultaneously. In my onclicklistener I have added ... public void onClick(View v) { mSoundManager.playSound(1); mSoundManager.playSound(2); } ... But this plays only one sound at a time, sound with index 1 followed by sound with index 2. How can I play atleast 2 sounds simultaneously using this code whenever there is an onClick() event? public class SoundManager { private SoundPool mSoundPool; private HashMap<Integer, Integer> mSoundPoolMap; private AudioManager mAudioManager; private Context mContext; public SoundManager() { } public void initSounds(Context theContext) { mContext = theContext; mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0); mSoundPoolMap = new HashMap<Integer, Integer>(); mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); } public void addSound(int Index,int SoundID) { mSoundPoolMap.put(1, mSoundPool.load(mContext, SoundID, 1)); } public void playSound(int index) { int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f); } public void playLoopedSound(int index) { int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, -1, 1f); } }

    Read the article

  • What is the best way to get an audio file duration in Android?

    - by Gilead
    Hi! I'm using a SoundPool [ 1 ] to play audio clips in my app. All is fine but I need to know when the clip playback has finished. At the moment I track it in my app by obtaining the duration of each clip using a MediaPlayer [ 2 ] instance. That works fine but it looks wasteful to load each file twice, just to get the duration. I could roughly calculate the duration myself knowing the length of the file (available from the AssetFileDescriptor [ 3 ]) but I'd still need to know the sample rate and the number of channels. I see two potential solutions to that problem: Figuring out when a clip has finished playing (doesn't seem to be possible with SoundClip). Having a class which could load just the header of an audio file and give me the sample rate/number of channels (and, ideally, the sample count to get the exact duration). Any suggestions? Thanks, Max The code I'm using at the moment (works fine but is rather heavy for the purpose): String[] fileNames = ... MediaPlayer mp = new MediaPlayer(); for (String fileName : fileNames) { AssetFileDescriptor d = context.getAssets().openFd(fileName); mp.reset(); mp.setDataSource(d.getFileDescriptor(), d.getStartOffset(), d.getLength()); mp.prepare(); int duration = mp.getDuration(); // ... } On a side note, this question has already been asked [ 4 ] but got no answers.

    Read the article

  • ViewPager cycle between views?

    - by Erdem Azakli
    I want my ViewPager implementation to cycle between views instead of stopping at the last view. For example, if I have 3 views to display via a ViewPager, it should return back to the first View after the third View on fling instead of stopping at that third view. I want it to return to the first page/view when the user flings forward on the last page Thanks, Mypageradapter; package com.example.pictures; import android.content.Context; import android.media.AudioManager; import android.os.Parcelable; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; public class MyPagerAdapter extends PagerAdapter{ SoundManager snd; int sound1,sound2,sound3; boolean loaded = false; public int getCount() { return 6; } public Object instantiateItem(View collection, int position) { View view=null; LayoutInflater inflater = (LayoutInflater) collection.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.setVolumeControlStream(AudioManager.STREAM_MUSIC); int resId = 0; switch (position) { case 0: resId = R.layout.picture1; view = inflater.inflate(resId, null); break; case 1: resId = R.layout.picture2; view = inflater.inflate(resId, null); break; case 2: resId = R.layout.picture3; view = inflater.inflate(resId, null); break; case 3: resId = R.layout.picture4; view = inflater.inflate(resId, null); break; case 4: resId = R.layout.picture5; view = inflater.inflate(resId, null); break; case 5: resId = R.layout.picture6; view = inflater.inflate(resId, null); break; } ((ViewPager) collection).addView(view, 0); return view; } @SuppressWarnings("unused") private Context getApplicationContext() { // TODO Auto-generated method stub return null; } private void setVolumeControlStream(int streamMusic) { // TODO Auto-generated method stub } @SuppressWarnings("unused") private Context getBaseContext() { // TODO Auto-generated method stub return null; } @SuppressWarnings("unused") private PagerAdapter findViewById(int myfivepanelpager) { // TODO Auto-generated method stub return null; } @Override public void destroyItem(View arg0, int arg1, Object arg2) { ((ViewPager) arg0).removeView((View) arg2); } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == ((View) arg1); } @Override public Parcelable saveState() { return null; } public static Integer getItem(int position) { // TODO Auto-generated method stub return null; } } OnPageChangeListener; package com.example.pictures; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.view.View; import android.widget.Button; import android.widget.Toast; public class Pictures extends Activity implements OnPageChangeListener{ SoundManager snd; int sound1,sound2,sound3; View view=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.picturespage); MyPagerAdapter adapter = new MyPagerAdapter(); ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager); myPager.setAdapter(adapter); myPager.setCurrentItem(0); myPager.setOnPageChangeListener(this); snd = new SoundManager(this); sound1 = snd.load(R.raw.sound1); sound2 = snd.load(R.raw.sound2); sound3 = snd.load(R.raw.sound3); } public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub } public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub } public void onPageSelected(int position) { // TODO Auto-generated method stub switch (position) { case 0: snd.play(sound1); break; case 1: snd.play(sound2); break; case 2: snd.play(sound3); break; case 3: Toast.makeText(this, "1", Toast.LENGTH_SHORT).show(); break; case 4: Toast.makeText(this, "2", Toast.LENGTH_SHORT).show(); break; case 5: Toast.makeText(this, "3", Toast.LENGTH_SHORT).show(); break; } } };

    Read the article

  • Change the playback rate of a track in real time on Android

    - by android_dev
    Hello, I would like to know if somebody knows a library to changing the playback rate of a track in real time. My idea is to load a track and change its playback rate to half or double. Firstly, I tried with MusicPlayer but is was not possible at all and then I tried with SoundPool. The problem is that with SoundPool I can´t change the rate once the track is loaded. Here is the code I am using (proof of concept): float j = 1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button b = (Button)findViewById(R.id.Button01); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { j = (float) (j +.5); } }); AssetFileDescriptor afd; try { SoundPool sp = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); afd = getAssets().openFd("wav/sample.wav"); int id = sp.load(afd, 1); sp.play(id, 1, 1, 1, 0, j); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } When I press the button, the playback rate should increase but it does not happen. Any idea of how change the rate in real time? Thanks in advance.

    Read the article

  • Complex sound handling (I.E. pitch change while looping)

    - by Matthew
    Hi everyone I've been meaning to learn Java for a while now (I usually keep myself in languages like C and Lua) but buying an android phone seems like an excellent time to start. now after going through the lovely set of tutorials and a while spent buried in source code I'm beginning to get the feel for it so what's my next step? well to dive in with a fully featured application with graphics, sound, sensor use, touch response and a full menu. hmm now there's a slight conundrum since i can continue to use cryptic references to my project or risk telling you what the application is but at the same time its going to make me look like a raving sci-fi nerd so bare with me for the brief... A semi-working sonic screwdriver (oh yes!) my grand idea was to make an animated screwdriver where sliding the controls up and down modulate the frequency and that frequency dictates the sensor data it returns. now I have a semi-working sound system but its pretty poor for what its designed to represent and I just wouldn't be happy producing a sub-par end product whether its my first or not. the problem : sound must begin looping when the user presses down on the control the sound must stop when the user releases the control when moving the control up or down the sound effect must change pitch accordingly if the user doesn't remove there finger before backing out of the application it must plate the casing of there device with gold (Easter egg ;P) now I'm aware of how monolithic the first 3 look and that's why I would really appreciate any help I can get. sorry for how bad this code looks but my general plan is to create the functional components then refine the code later, no good painting the walls if the roofs not finished. here's my user input, he set slide stuff is used in the graphics for the control @Override public boolean onTouchEvent(MotionEvent event) { //motion event for the screwdriver view if(event.getAction() == MotionEvent.ACTION_DOWN) { //make sure the users at least trying to touch the slider if (event.getY() > SonicSlideYTop && event.getY() < SonicSlideYBottom) { //power setup, im using 1.5 to help out the rate on soundpool since it likes 0.5 to 1.5 SonicPower = 1.5f - ((event.getY() - SonicSlideYTop) / SonicSlideLength); //just goes into a method which sets a private variable in my sound pool class thing mSonicAudio.setPower(1, SonicPower); //this handles the slides graphics setSlideY ( (int) event.getY() ); @Override public boolean onTouchEvent(MotionEvent event) { //motion event for the screwdriver view if(event.getAction() == MotionEvent.ACTION_DOWN) { //make sure the users at least trying to touch the slider if (event.getY() > SonicSlideYTop && event.getY() < SonicSlideYBottom) { //power setup, im using 1.5 to help out the rate on soundpool since it likes 0.5 to 1.5 SonicPower = 1.5f - ((event.getY() - SonicSlideYTop) / SonicSlideLength); //just goes into a method which sets a private variable in my sound pool class thing mSonicAudio.setPower(1, SonicPower); //this handles the slides graphics setSlideY ( (int) event.getY() ); //this is from my latest attempt at loop pitch change, look for this in my soundPool class mSonicAudio.startLoopedSound(); } } if(event.getAction() == MotionEvent.ACTION_MOVE) { if (event.getY() > SonicSlideYTop && event.getY() < SonicSlideYBottom) { SonicPower = 1.5f - ((event.getY() - SonicSlideYTop) / SonicSlideLength); mSonicAudio.setPower(1, SonicPower); setSlideY ( (int) event.getY() ); } } if(event.getAction() == MotionEvent.ACTION_UP) { mSonicAudio.stopLoopedSound(); SonicPower = 1.5f - ((event.getY() - SonicSlideYTop) / SonicSlideLength); mSonicAudio.setPower(1, SonicPower); } return true; } and here's where those methods end up in my sound pool class its horribly messy but that's because I've been trying a ton of variants to get this to work, you will also notice that I begin to hard code the index, again I was trying to get the methods to work before making them work well. package com.mattster.sonicscrewdriver; import java.util.HashMap; import android.content.Context; import android.media.AudioManager; import android.media.SoundPool; public class SoundManager { private float mPowerLvl = 1f; private SoundPool mSoundPool; private HashMap mSoundPoolMap; private AudioManager mAudioManager; private Context mContext; private int streamVolume; private int LoopState; private long mLastTime; public SoundManager() { } public void initSounds(Context theContext) { mContext = theContext; mSoundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0); mSoundPoolMap = new HashMap<Integer, Integer>(); mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); } public void addSound(int index,int SoundID) { mSoundPoolMap.put(1, mSoundPool.load(mContext, SoundID, 1)); } public void playUpdate(int index) { if( LoopState == 1) { long now = System.currentTimeMillis(); if (now > mLastTime) { mSoundPool.play(mSoundPoolMap.get(1), streamVolume, streamVolume, 1, 0, mPowerLvl); mLastTime = System.currentTimeMillis() + 250; } } } public void stopLoopedSound() { LoopState = 0; mSoundPool.setVolume(mSoundPoolMap.get(1), 0, 0); mSoundPool.stop(mSoundPoolMap.get(1)); } public void startLoopedSound() { LoopState = 1; } public void setPower(int index, float mPower) { mPowerLvl = mPower; mSoundPool.setRate(mSoundPoolMap.get(1), mPowerLvl); } } ah ha! I almost forgot, that looks pretty ineffective but I omitted my thread which actuality updates it, nothing fancy it just calls : mSonicAudio.playUpdate(1); thanks in advance, Matthew

    Read the article

  • How to retain the state of a activity that has a GLSurfaceView

    - by user348639
    My problem is our game can switch into menu and setting mode instantly but it will need 4-6 seconds to load texture, init GL render mode eventually I just used 6 simple textures to create 6 sprites in game. Please help me answer two questions: 1. How can I preload our assets in android os to start our game quicker? 2. In order to use a trick to create instance switch between activity, how can I retain my activity with GLSurfaceView state? I order to help you understanding my situation, please read the following code: The game using 3 activities as you can see in following configuration: <application android:label="@string/app_name" android:icon="@drawable/icon" android:allowBackup="true"> <activity android:name=".Menu" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleTop"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".ReTouch" android:screenOrientation="portrait" /> <activity android:name=".Preference" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" /> </application> My .ReTouch class is a class that extended from RokonActivity (I am using rokon engine for my game), this engine will create a GLSurefaceView to render my game in OpenGL ES You can get RokonAcitivity's source code here: http://code.google.com/p/rokon/source/browse/tags/release/1.1.1/src/com/stickycoding/Rokon/RokonActivity.java public class ReTouch extends RokonActivity { public static final int REPLAY_DELAY_INTERVAL = 1000; private ReTouchGameBoard reTouchGame; and .Menu, .Preference are two normal standard activity in an android application. I am using this method to start and switch between activities: playButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { soundPool.play(soundId, 1, 1, 1, 0, 1); startActivity(new Intent(Menu.this, ReTouch.class)); } }); settingButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { soundPool.play(soundId, 1, 1, 1, 0, 1); startActivity(new Intent(Menu.this, Preference.class)); } }); quitButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { soundPool.play(soundId, 1, 1, 1, 0, 1); finish(); } });

    Read the article

  • Error in eclipse on run android project

    - by Larz
    I am trying to get a simple hello world android project working in eclipse using an android emulator. I have been using the examples on developer.android.com. I actually did have a hello world app working. I then modified it's xml files to have a text input field and a button as in the second example shows on that site. This failed to run on the emulator. I then went back and tried to create another simple hello world project, but it fails to run. The console says "Waiting for HOME ('android.process.acore') to be launched, but nothing happens or sometimes a messenger in the emulator says "unfortunately Android Wear has stopped". Below is a sample error filter on the log file. I find trying to debug this is something new to me and I am not sure the best way to go about it. I am just trying to learn some basic android developer skills. 05-30 16:19:07.336: E/SELinux(469): SELinux: Loaded file_contexts from /file_contexts, 05-30 16:19:07.336: E/SELinux(469): digest= 05-30 16:19:07.376: E/SELinux(469): b0 05-30 16:19:07.376: E/SELinux(469): 4b 05-30 16:19:07.756: E/SELinux(469): 03 05-30 16:19:07.756: E/SELinux(469): 4a 05-30 16:19:07.826: E/SELinux(469): 73 05-30 16:19:07.886: E/SELinux(469): ab 05-30 16:19:07.886: E/SELinux(469): 6d 05-30 16:19:07.896: E/SELinux(469): 46 05-30 16:19:07.896: E/SELinux(469): b4 05-30 16:19:07.896: E/SELinux(469): a5 05-30 16:19:07.896: E/SELinux(469): 73 05-30 16:19:07.896: E/SELinux(469): 8a 05-30 16:19:07.896: E/SELinux(469): ee 05-30 16:19:07.896: E/SELinux(469): ac 05-30 16:19:07.906: E/SELinux(469): 68 05-30 16:19:07.906: E/SELinux(469): ff 05-30 16:19:07.906: E/SELinux(469): 04 05-30 16:19:07.906: E/SELinux(469): dc 05-30 16:19:07.906: E/SELinux(469): b8 05-30 16:19:07.906: E/SELinux(469): a2 05-30 16:19:11.806: E/SensorManager(511): sensor or listener is null 05-30 16:19:16.196: E/BluetoothAdapter(378): Bluetooth binder is null 05-30 16:19:16.206: E/BluetoothAdapter(378): Bluetooth binder is null 05-30 16:19:17.186: E/WVMExtractor(54): Failed to open libwvm.so: dlopen failed: library "libwvm.so" not found 05-30 16:19:17.776: E/AudioCache(54): Error 1, -2147483648 occurred 05-30 16:19:17.796: E/SoundPool(378): Unable to load sample: (null) 05-30 16:19:18.536: E/AudioCache(54): Error 1, -2147483648 occurred 05-30 16:19:18.546: E/SoundPool(378): Unable to load sample: (null)

    Read the article

  • Sound Effects/Manipulation?

    - by Adam
    Hello, I am creating an android app that basically records an applies an "Effect" on the audio track then plays it back. I got my app to record an play back but I am stuck an not sure where do go from here. I have been Googling for days now trying to find a open source audio library or some way to change the audio after I record it. I currently have it setup to play back using SoundPool an I't lets me speed up an slow down the audio. I would like to do things like change pitch an add echo etc. I will appreciate any responses because I am totally stumped right now. Thanks Adam

    Read the article

  • Why isn't multi-touch working for my imagebuttons?

    - by Droidy
    I'm using imagebuttons that play sounds using SoundPool. Here is example code of one of the imagebuttons: ImageButton Button1 = (ImageButton)findViewById(R.id.sound); Button1.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN ) { mSoundManager.playSound(1); return false; } return false; } }); For some reason, it doesn't allow you to click multiple buttons at the same time. Is it because I'm building for 1.6 SDK? Thanks!

    Read the article

  • Playing BG Music Across Activities in Android

    - by scarface
    Hello! First time to ask a question here at stackoverflow. Exciting! Haha. We're developing an Android game and we play some background music for our intro (we have an Intro Activity) but we want it to continue playing to the next Activity, and perhaps be able to stop or play the music again from anywhere within the application. What we're doing at the moment is play the bgm using MediaPlayer at our Intro Activity. However, we stop the music as soon as the user leaves that Activity. Do we have to use something like Services for this? Or is MediaPlayer/SoundPool enough? If anyone knows the answer, we'd gladly appreciate your sharing it with us. Thanks!

    Read the article

  • What happens when I release a upgrade with higher targeted sdk as previous version?

    - by Peterdk
    SoundPool has a serious bug in it in Android 1.5. I fixed it with a workaround, but since it really limits my app, I want to target 1.6+ for the next version of it. I am wondering: What happens when I release a upgrade that has a higher target SDK version then the previous version of my app? Will only 1.6+ users be able to upgrade their app? Or will also the 1.5 users be able to upgrade since they have the program already installed? Anybody experience with this?

    Read the article

1