android-mediaplayer

How to create Button to control background sound.

ε祈祈猫儿з 提交于 2019-12-12 00:13:28
问题 I'm trying to add background music to my application. All I want is the sound should played on pressing the btnoptn Button and its text transitions into the "music off". The music should continue on any Activity until the settings page is returned to and the same Button is pressed again. The music then stops and the Button text changes to "music on". This my code so far: package hello.english; import hello.english.R; import android.app.Activity; import android.content.Intent; import android

mediaplayer stop sound after 30 click?

久未见 提交于 2019-12-11 20:28:35
问题 hi I would like to ask why is that after clicking a button w/ sound 30 times on the 31 onwards the sound will no longer be heard and will hang after a few more click? can anyone please help me? thanks in advance here is my code. SharedPreferences soundPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); boolean sound = soundPrefs.getBoolean("Sound", true); MediaPlayer clickLetters = MediaPlayer.create(Gameplay.this, R.raw.click_letters); switch(v.getId()) { case R.id.btnA:

Android: Activity also calling other Service of the application, which is not called

末鹿安然 提交于 2019-12-11 18:28:07
问题 I creating an android app which basically contains 2 media players . One that plays music from phone memory & other that plays streams from internet(URLs). Each media player is defined in its separate activity . I'm using Service to playback. (i.e. when the user presses the play button, a Service gets started & plays the media). The MusicPlayer is the default activity of the application & is in the package com.example.musicplayer . Whereas, the stream player is in the different package com

Setting a file from asset folder causes MediaPlayer to nullpointer exception

故事扮演 提交于 2019-12-11 16:15:23
问题 I have a list of asset folder files, named filelist . I show all that elements in the ListView, so when some of them has been clicked i want it to be played. And here it gives me nullpointerexception . Code, that causes an error: try { selectedItemPlayer.setDataSource( aMan.openFd(filelist[selectedItem]).getFileDescriptor(), aMan.openFd(filelist[selectedItem]).getStartOffset(), aMan.openFd(filelist[selectedItem]).getLength()); selectedItemPlayer.prepare(); selectedItemPlayer.start();

why my video doesnot fit the size of the texture as i change the size of the texture

五迷三道 提交于 2019-12-11 16:08:24
问题 Iam trying to animate a video rendered using texture view, the animation works fine , but when i scale the texture to a different size the media player does not scale to fit the size of the texture,the video is always playing full screen in the background and i can only see part of the video when i scale the texture my code works fine on some android devices running android 4.0 but does not work on devices with later versions of android . heres my code for the animation kindly tell me where

Playing and Releasing audio in RecyclerView

三世轮回 提交于 2019-12-11 16:04:58
问题 I'm learning android and currently RecyclerView, so in this example I'm playing a specific raw sound file when clicking a play button and then releasing it when it's done. I could seriously use some pointers on what is the best practice however as I have a few issues and questions: I have a problem with transiting states so if I press play very quickly I'll get an IllegalStateException , probably from trying to release an already released player. I should apparently also nullify after release

Android getDuration for video gets different value on different versions

别说谁变了你拦得住时间么 提交于 2019-12-11 14:49:45
问题 I'm trying to play the following video on all devices. The problem is that with Android 4.1.2 the getDuration is 1476000 AKA 24:36 minutes. With Android 5.0.2 the getDuration returns 1546347 AKA 25:46 minutes. So on Android 4.1.2 the real problem is that the video continues to play after "being finished". But the reality is that the video should have a getDuration like on Android 5.0.2. Does anyone here have any clue? To see the UI problem: http://i.stack.imgur.com/tRAg5.jpg Code below:

How to check a video has sound or not in Android?

这一生的挚爱 提交于 2019-12-11 14:36:30
问题 I am using a TextureView with a MediaPlayer to play an mp4 video from a url. Is there any way I can programatically check if the video I am playing has sound? Edit: I'm using API 14, so I don't have access to the MediaPlayer method getTrackInfo Many Thanks 回答1: In API level 16 or later, the MediaPlayer class has a getTrackInfo method that returns a TrackInfo[]. You could then call getTrackType for each element in the array and see if you get MEDIA_TRACK_TYPE_AUDIO . 来源: https://stackoverflow

Error Codes Media Player syntax and definition

主宰稳场 提交于 2019-12-11 14:19:59
问题 I cannot find any documentation on error codes with regard to Android. I am putting together an app that seemed to be working on a lower level API setup but not on a higher one. The error occurs when trying to play an audio file and like I said it all worked in a lower version. The error code I see is in the log are: MediaPlayer info/warning (1, 32) MediaPlayer Info (1,32) MediaPlayer info/warning (1,26) MediaPlayer Info (1,26) MediaPlayer error(351, -4) MediaPlayer Error(351,-4) VideoView

java.lang.IllegalStateException in MediaPlayer.setDataSource, using Ringtone class

前提是你 提交于 2019-12-11 13:57:11
问题 I had a crash reported by an user (Samsung Galaxy S5, Android 4.4) and I do not understand what is happening. It seems imporbable but maybe some people have encountered the same problem, or similar. Here is the trace: java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:300) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355) at java.util.concurrent.FutureTask.setException(FutureTask.java:222) at java