MediaPlayer.setDataSource(String) not working with local files

Alternative Solution #1: Using Resources.getIdentifier() Why not use getResources().getIdentifier() to get id of the resource and use the static MediaPlayer.create() as usual? public int getIdentifier (String name, String defType, String defPackage) getIdentifier() takes your resource name (test0), resource type(raw), your package name and returns the actual resource id. MediaPlayer mp; //String filename = “android.resource://” + … Read more

Media Session Compat not showing Lockscreen controls on Pre-Lollipop

While not strictly required for MediaSession, RemoteControlClient used on API14-19 devices, does require audio focus and it is 100% strongly recommended for all media playback. Adding lines such as: AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int result = audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (result != AudioManager.AUDIOFOCUS_GAIN) { return; //Failed to gain audio focus } Before playing any … Read more

Android – play sound on button click – Null pointer exception

Thanks you for your answers! Appreciate it! Here’s how I finally managed to get it work: button[i].setOnClickListener(new OnClickListener() { public void onClick(View view) { mp = MediaPlayer.create(Test.this, R.raw.mysound); mp.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub mp.release(); } }); mp.start(); } });

Why does it take so long for Android’s MediaPlayer to prepare some live streams for playback?

It does appear that it is buffering a fixed amount of data rather than a fixed amount of time. For anyone who doesn’t know the bitrates of various types of NPR streams off the top of their head, the data looks like: MPR news stream: 27 seconds (http://newsstream1.publicradio.org:80/), 64 kbps MPR classical music stream: 15 … Read more

How to fit video in Live wallpaper, by center-crop and by fitting to width/height?

You can achieve this with a TextureView. (surfaceView won’t work either).I have found some code which will help you for achieving this. in this demo you can crop the video in three type center, top & bottom. TextureVideoView.java public class TextureVideoView extends TextureView implements TextureView.SurfaceTextureListener { // Indicate if logging is on public static final … Read more

SeekBar and media player in android

To create a ‘connection’ between SeekBar and MediaPlayer you need first to get your current recording max duration and set it to your seek bar. mSeekBar.setMax(mFileDuration/1000); // where mFileDuration is mMediaPlayer.getDuration(); After you initialise your MediaPlayer and for example press play button, you should create handler and post runnable so you can update your SeekBar … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)