android-mediaplayer

MediaPlayer seekTo doesn't work

﹥>﹥吖頭↗ 提交于 2019-12-11 08:57:38
问题 If I call seekTo before start, an audio starts from beginning. Is it possible to start playing audio from a specific point? Thanks! 回答1: It seems to be a bug on Android platform, and so far it hasn't been fixed. See this issue here. 回答2: I've just experienced the same issue. The solution was to use MediaPlayer.OnSeekCompleteListener . However in my case there weren't any problems with calling seekTo before start if the audio file was relatively short, but if it became longer then it seemed

Play two mp3 song at the same time

回眸只為那壹抹淺笑 提交于 2019-12-11 08:36:46
问题 I want to play two song (mp3) at the same time (one is karaoke file and one is the record audio by user). Can I use the MediaPlayer to do this? If so, is that right if I create 2 object of MediaPlayer and setDataSource for two file and play it? Thanks! 回答1: Yes, According to me that's all fine using two MediaPlayer objects and do that, In my experience of doing same there has been no any problems for sound play or any memory issues,that work like charm. 来源: https://stackoverflow.com/questions

Error while trying to retrieve Metadata from a remote MP3 file Android

若如初见. 提交于 2019-12-11 08:33:27
问题 I'm working on a Radio Streming application for Android. The music is well recieved and played by the MediaPlayer class, but the problem is when I try to retrieve the Metadata, the App blocks and returns errors. This is the code: package com.tests.mediaplayer1; import java.io.IOException; import android.media.AudioManager; import android.media.MediaMetadataRetriever; import android.media.MediaPlayer; import android.os.Bundle; import android.app.Activity; import android.content.Context; import

Seting the duration of Media Player media in Android

故事扮演 提交于 2019-12-11 08:26:33
问题 I want to set the time duration for MediaPlayer . Here is my code: MediaPlayer play = MediaPlayer.create(getApplicationContext(),R.raw.beepsound); play.start(); 回答1: You can use Timer which will be updated every 1000 milliseconds. Then set time to a TextView or what ever you want. if (player != null) { player.start(); timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { if (player != null &&

Android Mediaplayer multiple instances when activity resumes

青春壹個敷衍的年華 提交于 2019-12-11 07:57:26
问题 I am developing an app that plays a stream by using the built-in Android Mediaplayer. Everything works fine apart the fact that when I press the "home" button and then open the activity again, the app just starts a new instance of the mediaplayer and I can hear the stream twice without the possibility to stop the first one. Scenario. My app is only made of one activity. I open my app first time and the stream starts. Push the home button and the activity is "minimized" but the music still

Android MediaMetadataRetriever fails to load metadata on old Samsung devices

时光毁灭记忆、已成空白 提交于 2019-12-11 07:26:45
问题 I'm facing a strange issue when using the android.media.MediaMetadataRetriever. It fails to extract the video width from video files on Samsung phones with Android version 4.0.4 and 4.1.2. The call metaRetriever.extractMetadata() seems to return either null or an empty string, as users of my app are reporting the VideoSetupException with error code ASVF_3. It works on the Google emulators with said Android versions and all other Android versions and devices. Any idea what might be causing

MediaPlayer playing sound but not video

情到浓时终转凉″ 提交于 2019-12-11 06:46:20
问题 I'm trying to play a video from Android using a SurfaceView . I can load the video, the sound is played correctly but I can't see the video. Here is my activity : public class VideoTest extends Activity implements OnBufferingUpdateListener, OnCompletionListener, OnPreparedListener, OnVideoSizeChangedListener, SurfaceHolder.Callback, OnErrorListener { private static final String TAG = "MediaPlayerDemo"; private int mVideoWidth; private int mVideoHeight; private MediaPlayer mMediaPlayer;

Button Click Sound MediaPlayer Crashes If Buttons Are Pressed Too Rapidly

谁说我不能喝 提交于 2019-12-11 06:39:16
问题 Similar questions to this one are asked a lot, and I have looked at other answers. What they say is that in order to play a sound (in this case "tock.wav", which is located in the assets folder) whenever a button is clicked, you should do the following: public void onClick(View button) { playButtonClickSound(); } private void playButtonClickSound() { if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); mMediaPlayer.reset(); } try { AssetFileDescriptor afd; afd = getAssets().openFd("tock.wav")

Android: Mediaplayer keeps playing in background. How to stop it?

前提是你 提交于 2019-12-11 04:23:21
问题 I have developed an Android app, where the user can play a sound by clicking on a button, in a certain fragment. However, when you exit this fragment or close the app it keeps playing. How do I stop it if one exits the fragment or closes the app? This is how I play the sound: public class PageFragment_Bon extends Fragment implements View.OnClickListener{ public static final String ARG_PAGE = "ARG_PAGE"; private int mPage; private Button start, stop, replay; private MediaPlayer mediaPlayer;

MediaPlayer freezes instead of looping video on Android 4.4

≯℡__Kan透↙ 提交于 2019-12-11 04:08:44
问题 I am having a problem with video playback on Android 4.4 on the Galaxy Tab 3. The issue did not occur with the previous Android version 4.2. The issue I am playing a video in a loop. This worked very well for all users, until the Tab 3 got updated to Android 4.4. Since then the video freezes after the first loop (it gets stuck on the first frame of the video to be precise). I can reproduce that behaviour, and at the moment the video freezes my LogCat starts getting full with the following