media-player

how to shuffle list song with Media Player android

心已入冬 提交于 2019-12-24 07:04:13
问题 I've done shuffle in mediaplayer for a list of songs but dos not correct work please help: @Override public void onCompletion(MediaPlayer mediaPlayer) { if (isShuffle) { if (intent.hasExtra("songIndex")) { Random random = new Random(); songIndex = random.nextInt((songList.size() - 1) + 1); playSongWithIndex(songIndex); } } } and method for play song : public void playSongWithIndex(final int songIndex) { progressBar.setVisibility(View.VISIBLE); if (music_exist.exists()) { playMusicOfflineMode(

Android Mediaplayer Error (-19, 0)

不问归期 提交于 2019-12-24 06:28:10
问题 I try to replay a sound when I click on a button. But I get the Error (-19, 0) (what ever this means^^) My code: final Button xxx = (Button)findViewById(R.id.xxx); xxx.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.plop); mp.start(); } }); What is my mistake? 回答1: I was getting the same problem, I solved it by adding the following code: mp1 = MediaPlayer.create(sound.this, R.raw.pan1); mp1.start(

Mediaplayer plays twice

时光毁灭记忆、已成空白 提交于 2019-12-24 02:42:40
问题 I have a media player but when another file is selected it continues to play the old file and new one so it is playing two files at once here is my onCreate method private MediaPlayer mediaplayer = new MediaPlayer(); private Handler handler = new Handler(); @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.songplaying); // Getting Our Extras From Intent Bundle names = getIntent()

Not able to check Android Service Issue

老子叫甜甜 提交于 2019-12-24 02:22:39
问题 All I want to do is simply control background music in my app through a service so I am able to start it and stop it from any activity. I have everything set up perfectly when I tell the service to Toast when it is started and destroyed but as soon as I put the media play-in in there instead It starts fine and starts playing the music but as soon as a click a button to stop the service I get an error and a force close. Can anyone suggest what I am doing wrong? Here is my code: import android

Android: Simple how to stop mediaplayer after given time

元气小坏坏 提交于 2019-12-24 00:48:36
问题 I am trying to play an mp3 file (with an onClickListener) and stop after 2 seconds. I tried the code below but it is not working. Could anyone please help? final MediaPlayer mpsound = MediaPlayer.create(this, R.raw.media_player_sound); ImageView sound = (ImageView) findViewById(R.id.button); sound.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { mpsound.start();{ sleep(2000); mpsound.stop(); } } }); 回答1: Why are you calling stop() on mpfrog if you are playing

How to Pause Media Playback in UIWebView

随声附和 提交于 2019-12-23 18:19:48
问题 I am currently working on a browser that supports multiple tabs on the iPad. Problem is iOS doesn't allow for more than one tab to be playing audio/video at the same time, trying this causes issues to arise such as all the audio to stop and not come back. I have noticed that Google Chrome's browser actually stops the media in the tab that goes inactive. I am wondering how they go about it. I know it is possible to completely stop the media via a [webView loadRequest:NSURLRequestWithString(@

MPRemoteCommandCenter pause/play button not toggling?

杀马特。学长 韩版系。学妹 提交于 2019-12-23 07:28:25
问题 I'm having issues getting the play and pause buttons toggle in the MPRemoteCommandCenter. For whatever reason the audio and events will all work correctly, but the command center doesn't change the play button to the pause button. Here's my code... - (void)setupMPRemoteCommandCenter{ MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter]; MPRemoteCommand *play = [commandCenter playCommand]; [play setEnabled:YES]; [play addTarget:self action:@selector(playAudio:)];

JavaFX MediaPlayer: MP4 Won't Loop on Windows 7

雨燕双飞 提交于 2019-12-23 06:51:34
问题 I've created a basic JavaFX Media Player. On my Windows 10 OS, everything works fine, and it functions exactly as it's supposed to. private MediaPlayer initializeMediaPlayer(){ Media media = new Media(getClass().getResource("1-1.mp4").toString()); MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.setAutoPlay(true); mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE); mediaPlayer.setRate(1.25); mediaPlayer.setMute(true); return mediaPlayer; } Yet, when I run this code on Windows 7,

JavaFX MediaPlayer: MP4 Won't Loop on Windows 7

烈酒焚心 提交于 2019-12-23 06:51:13
问题 I've created a basic JavaFX Media Player. On my Windows 10 OS, everything works fine, and it functions exactly as it's supposed to. private MediaPlayer initializeMediaPlayer(){ Media media = new Media(getClass().getResource("1-1.mp4").toString()); MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.setAutoPlay(true); mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE); mediaPlayer.setRate(1.25); mediaPlayer.setMute(true); return mediaPlayer; } Yet, when I run this code on Windows 7,

How to check if mediaplayer is playing or stopped?

时光总嘲笑我的痴心妄想 提交于 2019-12-23 01:51:32
问题 How can I check whether the mediaplayer is playing or stopped, using Java Media Framework? 回答1: You can call getState and check against Controller.Started: if (mediaPlayer.getState() == Controller.Started) 回答2: // Register ControllerListener : public class myPlayer implements ControllerListener { // .... Player player = Manager.createRealizedPlayer(url); player.addControllerListener(this); // .... // And check for EndOfMedia event in the controllerUpdate method: public void controllerUpdate