android-mediaplayer

Using MediaPlayer to play the same file multiple times with overlap

别说谁变了你拦得住时间么 提交于 2019-12-21 12:16:26
问题 What's currently happening with my android application: I mapped a simple image to a button and have it play a sound on click. On each click, I create a MediaPlayer object with a sound file in my raw folder, I set an OnClickListener for that MediaPlayer object which stops playing the file and releases it, and then I play the MediaPlayer object. The code for the defined section: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main

How to filter out only relevant Media files in Android?

我们两清 提交于 2019-12-21 07:55:35
问题 I'm trying to fetch all the music files in my phone: For this I'm using: String[] STAR = {"*"}; Uri allExternalSongUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"; Cursor cursor = getContentResolver().query(allExternalSongUri, STAR, selection, null, null); if(cursor != null){ if(cursor.moveToFirst()){ do { String songName = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)); Log.i("name", songName); }

Get the mediaPlayer of the videoView in Android

*爱你&永不变心* 提交于 2019-12-21 06:58:36
问题 Is it possible to get a reference to the mediaPlayer instance that the videoView is using, preferably right inside its ctor? If so, how? Since the videoView doesn't have as much listeners as the mediaPlayer, I would like to have the ability to reach the mediaPlayer for extra control and better events handling. 回答1: you can listener from VideoView. VideoView mVideoView=new VideoView(); mVideoView.setOnPreparedListener( new MediaPlayer.OnPreparedListener() { @Override public void onPrepared

Serve mp3 stream for android with Laravel

匆匆过客 提交于 2019-12-21 05:29:06
问题 Here's my problem: I'm writing a laravel backend which have to serve an mp3 file that had to be reproduced by using the android standard media player. For the laravel backend I need to use JWT to handle authentication so on every request headers I have to set the "Authorization" field to " Bearer {token} " . The laravel route is " /songs/{id} " and is handled in this way: public function getSong(Song $song) { $file = new File(storage_path()."/songs/".$song->path.".mp3"); $headers = array();

Play audio using base64 data in html5

瘦欲@ 提交于 2019-12-21 04:51:28
问题 I have created one application to record audio using native mediaPlayer, converting this audio file into base64 data, passing this in html5 audio tag as below, File file = new File(Environment.getExternalStorageDirectory()+"/"+ "audiofile"+"/"+"myAudio.mp3"); byte[] FileBytes =getBytesFromFile(file); String base64 = Base64.encodeToString(FileBytes, Base64.NO_WRAP).toString(); public static byte[] getBytesFromFile(java.io.File file) throws IOException { InputStream is = new FileInputStream

Android WebView HTML5 Video Spawns MediaPlayer that lives forever on Samsung S4 [Hacked answer found]

霸气de小男生 提交于 2019-12-21 04:42:19
问题 From what I have been able to find out, this seems to be specific to recent Samsung devices. The S4 will do this. The Nexus 7 will not. If a WebView with a WebChromeClient begins to play an HTML5 video, it creates a MediaPlayer instance. Once the video is over, there doesn't seem to be a way to kill the MediaPlayer short of System.exit(0). This is my entire MainActivity.java package com.test.webviewtest; import android.app.Activity; import android.os.Bundle; import android.webkit

How to play default TICK sound?

↘锁芯ラ 提交于 2019-12-20 10:35:31
问题 I want to connect Android OS default tick sound (for example, the sound you hear when you long click Home button and select previous app to start) with my button click. I know how to play sounds via MediaPlayer, but I do not know where to search for this default tick sound. It had to be in some default resources, but I could not find it. MediaPlayer mp = MediaPlayer.create(getBaseContext(), sound); mp.setLooping(false); mp.start(); Anyone can help? PS. this sound will be activated inside of

Media Session Compat not showing Lockscreen controls on Pre-Lollipop

ⅰ亾dé卋堺 提交于 2019-12-20 08:36:48
问题 I'm using MediaSessionCompat from AppCompat Support Library Revision 22. And on Lollipop I'm getting notification & also the background of lockscreen is the album art. And everything works cool. While on Pre-Lollipop devices, the music controls on lockscreen are not at all shown. It's weird & I tried everything but it doesn't show up, not even the background changes. I hope someone has solution to this issue. Note: RemoteControlClient used to work on Lollipop & KitKat /** * Initializes the

How to play mp3 continuosly when application starts and stop when user close app in background

自闭症网瘾萝莉.ら 提交于 2019-12-20 06:35:41
问题 I am writing an app in which i am allowing user to view images and select one of them to set an WALLPAPER, and in this i also want to play an mp3 when user starts an App and stop that mp3 when user close application I have stored an MP3 Music file in res/raw folder namely : mymusic.mp3 I know how to play and stop MP3 music by using click on button, but don't know how to play mp3 in background continuosly, play when user start an app and stop when user close an app. Please someone help me, its

android-list of installed media players

独自空忆成欢 提交于 2019-12-20 06:10:34
问题 I know that this post is like this question : How to get a list of installed media players but i tried to test the code and it crashes ! this is the code : public class Newactivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.display); Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.withAppendedPath(MediaStore.Video.Media.INTERNAL_CONTENT_URI,"1"); intent.setData(uri); List<ResolveInfo>