Error 1 4 Android Media Player
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions android media player review you might have Meta Discuss the workings and policies of
Android Media Player Apk
this site About Us Learn more about Stack Overflow the company Business Learn more about hiring android media player kodi developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is android media player download a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Android Media player error (1,-4) while playing an audio from Assets folder up vote 6 down vote favorite 2 I need your help. I tried to play an audio file stored in
Android Portable Media Player
Assets folder but an error occurred. Here are my code: try{ if (player.isPlaying()) { player.stop(); player.release(); } }catch(Exception e){ Toast.makeText(this, "an exception occurred", Toast.LENGTH_LONG).show(); e.printStackTrace(); } try{ AssetFileDescriptor afd = BeeDailyConvo.this.getAssets().openFd("sounds/hello_kr.wma"); player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength()); player.prepare(); player.start(); }catch(Exception e){ e.printStackTrace(); } And here are my logcat: 06-16 22:39:53.330: W/MediaPlayer(13490): info/warning (1, 26) 06-16 22:39:53.330: E/MediaPlayer(13490): error (1, -4) Could you please explain what's wrong with my code? Thank you in advance Regards, Priska android android-mediaplayer share|improve this question edited Mar 14 '13 at 8:53 dda 4,74611228 asked Jun 16 '12 at 15:59 Priska Aprilia 3811314 add a comment| 5 Answers 5 active oldest votes up vote 4 down vote accepted This issue has been SOLVED. The asset file descriptor must be closed before preparing the player. This is how I solved the problem: player = new MediaPlayer(); AssetFileDescriptor afd = BeeDailyConvo.this.getAssets() .openFd("sounds/"+file); player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength()); afd.close();**//just added this line** player.prepare(); player.start(); share|improve this answer edited Mar 14 '13 at 8:54 dda 4,7
here for a quick overview of the site Help Center Detailed answers to android windows media player any questions you might have Meta Discuss the workings and best android media player policies of this site About Us Learn more about Stack Overflow the company Business Learn more
Android Media Player Tutorial
about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community http://stackoverflow.com/questions/11064990/android-media-player-error-1-4-while-playing-an-audio-from-assets-folder Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error code 1,-4 in media player android up vote 1 down vote favorite I got error code with 1,-4 number in android media player I use this code http://stackoverflow.com/questions/9325895/error-code-1-4-in-media-player-android for playing music in my service public void playNextSong(/* String manualUrl */) { mState = State.Stopped; relaxResources(true); // release everything except MediaPlayer AudioFile file = playList.nextFile(); if (file == null) { say("Tidak ada lagu di playlist"); return; } try { // set the source of the media player a a content URI createMediaPlayerIfNeeded(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mPlayer.setDataSource(getApplicationContext(), file.getUri()); mState = State.Preparing; // MUST call this! setUpAsForeground(file.getTitle() + " (loading)"); // starts preparing the media player in the background. When it's // done, it will call // our OnPreparedListener (that is, the onPrepared() method on this // class, since we set // the listener to 'this'). // // Until the media player is prepared, we *cannot* call start() on // it! mPlayer.prepareAsync(); } catch (IOException ex) { Log.e("MusicService", "IOException playing next song: " + ex.getMessage()); ex.printStackTrace(); } } And I use this in the shake listener of my code mSensorListener .setOnShakeListener(new ShakeEventListener.OnShakeListener() { public
here for a quick overview of the site Help Center Detailed answers http://stackoverflow.com/questions/11970574/android-mediaplayer-not-preparing-error-1-4 to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack media player Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Android MediaPlayer not preparing. Error (1, -4) up vote 0 down vote favorite So I've been trying to make a simple sound effect app for android media player android. Here is the relevant code: public static final String LOG_TAG = "BCA"; public MediaPlayer mp; @Override public void onCreate(Bundle savedInstanceState) { Log.v(LOG_TAG, "creating"); super.onCreate(savedInstanceState); setContentView(R.layout.main_list); mp = new MediaPlayer(); mp.setAudioStreamType(AudioManager.STREAM_MUSIC); Log.v(LOG_TAG, "set stream type"); playSound(); } public void playSound() { try { mp.setDataSource("R.raw.sound1"); Log.v(LOG_TAG, "set data source"); mp.setOnPreparedListener(this); mp.setOnErrorListener(this); mp.prepareAsync(); Log.v(LOG_TAG, "preparing"); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void onPrepared(MediaPlayer mediaPlayer) { Log.v(LOG_TAG, "finished preparing; starting"); mp.start(); Log.v(LOG_TAG, "started music"); } public boolean onError(MediaPlayer mp, int e, int f) { Log.v(LOG_TAG, "There was an error"); Log.v(LOG_TAG, mp + " " + e + " " + f); mp.reset(); return true; } Basically it gets to the set "set data source" tag but never finishes preparing. the error code is (1, 4) the 1 apparently being an unknown error. I have used multiple