android-mediaplayer

How to stop Service when app is paused or destroyed but not when it switches to a new Activity?

情到浓时终转凉″ 提交于 2019-12-10 15:38:40
问题 Currently I have a Service which I am using to play a sound file in the background whilst the app is open: public class BackgroundSoundService extends Service { MediaPlayer player; public IBinder onBind(Intent arg0) { return null; } @Override public void onCreate() { super.onCreate(); player = MediaPlayer.create(this, R.raw.sound); player.setLooping(true); player.setVolume(100, 100); } public int onStartCommand(Intent intent, int flags, int startId) { player.start(); return 1; } @Override

Visualizer output in Android depends on the device volume

人走茶凉 提交于 2019-12-10 14:28:38
问题 There was such a question already, but it seems like the workaround suggested there doesn't work at all. The Visualizer's output is still affected by the global volume and consists of zeroes when the volume is turned all the way down but the MediaPlayer is still playing. Here's my code to reproduce this issue: player=new MediaPlayer(); player.setAudioSessionId(SHARED_SESSION_ID); try { player.setDataSource("https://example.com/song.mp3"); player.setOnPreparedListener(new MediaPlayer

How to change the media player from a different activity

允我心安 提交于 2019-12-10 12:22:23
问题 I was wondering if I can declare a media player variable in one activity and then pause or stop it in a separate activity. How would I go about this or is there another way? Thanks 回答1: I am not a fan of static vars. I'd prefer doing something like this Android Manifest <activity name="Player" android:launchMode="singleTop"/> This former ensures that you have only one instance of the activity running, and that all intents leading to starting that activity are delivered via its onNewIntent()

Seeking / start media at desired position on Chromecast from Android from my own webserver

时间秒杀一切 提交于 2019-12-10 11:54:46
问题 I am currently developing a media application for Android that can cast it's media to a Google Chromecast. This application is not meant to be published so some of the unorthodox choices I have made (web server, local files etc.) isn't part of the discussion. The problem is that when I load a media stream to the Chromecast, or seek in the stream, it doesn't change. The callback says it succeeds, but the movie keeps playing from scratch (when I load with initial position) and doesn't change

support full swing android media decoder?

青春壹個敷衍的年華 提交于 2019-12-10 11:54:41
问题 When I decode a full swing video using Android MediaCodec class, the output is always in studio swing? am I missing a header in the video file? I know after Android 24, I can use MediaFormat class to set COLOR_RANGE_FULL ? Any help on this? seems like even setting MediaFormat.setInteger(MediaFormat.KEY_COLOR_RANGE, MediaFormat.COLOR_RANGE_FULL); Also doesn't help on android 24. 回答1: I talked to engineers from Android team at Google, and they mentioned this part of the code should be

android get screenshot of current videoview

一个人想着一个人 提交于 2019-12-10 07:00:53
问题 I've seen a lot of old questions about this, maybe now there are some solutions. I want to take a screenshot of the current frame of my videoview. Videoview shows a real-time video using a rtsp-stream. I try to take bitmap, but it's always black public static Bitmap loadBitmapFromView(View v) { Bitmap b = Bitmap.createBitmap(v.getLayoutParams().width , v.getLayoutParams().height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams()

Cannot get android MediaPlayer onCompletion to fire

橙三吉。 提交于 2019-12-10 01:06:33
问题 I'm trying to use the android MediaPlayer class to play some sounds. Here's the code MediaPlayer mp = new MediaPlayer(); mp.setDataSource(context, Uri.parse(soundUrl)); mp.setAudioStreamType(AudioManager.STREAM_MUSIC); mp.setLooping(false); mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { Log.i(LOGTAG, "onComplete hit"); mp.stop(); mp.release(); } }); mp.prepare(); mp.start(); This code runs in a service, but for some

Android Media player error (1,-4) while playing an audio from Assets folder

和自甴很熟 提交于 2019-12-09 17:58:58
问题 I need your help. I tried to play an audio file stored in 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

Android MediaPlayer - setDataSource and Release - IllegalStateException

坚强是说给别人听的谎言 提交于 2019-12-09 14:48:01
问题 I wrote my own MediaPlayer class to play files at a specific path and to play files from the assets folder. Here is the class: public class CMediaPlayer extends MediaPlayer{ public void play(String audioPath){ this.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.release(); } }); File f = new File(audioPath); if(f.exists()){ try{ FileInputStream fis = new FileInputStream(f); FileDescriptor fileD = fis.getFD(); this.setDataSource

Progressive audio caching library for Android

为君一笑 提交于 2019-12-09 13:15:17
问题 I'm using an android MediaPlayer class right now for progressive audio streaming like this: MediaPlayer mp = new MediaPlayer(); mp.setDataSource(audioUrl); mp.prepare(); mp.start(); But MediaPlayer class doesn't provide any caching, and I always need to do this routine: unnecessary network and battery waste So, can someone help me find some library that will provide caching, because I couldn't find any. Thanks 回答1: Looking my projects: https://github.com/master255/ImmortalPlayer One thread to