media-player

How to implement an audio player for Android using MediaPlayer And MediaController?

China☆狼群 提交于 2019-11-27 20:03:52
问题 I want to create an Android application that is a client for an Internet radio station. And I want it look native to Android? But im confused with Android API logic and documentation. What i've got is that I need MediaPlayer and MediaController classes. Am I right, and is there any good example of AUDIO player for Android? Especially, I'm very interested how to use MediaPlayer and MediaController classes together. UPD: Finally I've got the code, that does exactly what I want: Intent i = new

How to get current playing song details from MediaPlayer

泪湿孤枕 提交于 2019-11-27 18:24:31
Is there any way to get the details of current song played by MediaPlayer ? Just for reference, this works: import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.util.Log; public class MediaPlayer extends Activity { public static final String SERVICECMD = "com.android.music.musicservicecommand"; public static final String CMDNAME = "command"; public static final String CMDTOGGLEPAUSE = "togglepause"; public static final String CMDSTOP =

how to get file name from URI

孤人 提交于 2019-11-27 17:57:29
问题 Hello I am develop video player with android gallery. I receive URI from gallry. and I need to display video title, when play video. so if content has not title meta data. I need to disaplay video file name. How to get video content file name? thank you 回答1: Here is the code for getting name of file from url Uri u = Uri.parse("www.google.com/images/image.jpg"); File f = new File("" + u); f.getName(); 回答2: Since none of the answers really solve the questions, i put my solution here, hope it

Stream live video from phone to phone using socket fd

醉酒当歌 提交于 2019-11-27 17:24:37
I am new to android programming and have found myself stuck I have been researching various ways to stream live video from phone to phone and seem to have it mostly functional, except of course the most important part: playing the stream. It appears to be sending the stream from one phone, but the second phone is not able to play the stream. Here is the code for the playing side public class VideoPlayback extends Activity implements Callback { MediaPlayer mp; private SurfaceView mPreview; private SurfaceHolder holder; private TextView mTextview; public static final int SERVERPORT = 6775;

Android: Mediaplayer: How to use SurfaceView or mediaplayer to play video in correct size

可紊 提交于 2019-11-27 17:21:27
I am playing local video file using MediaPlayer and SurfaceView. SurfaceView is the only control in activity, while my video files are QVGA or other. Problem is that video is getting stretched, How can i play video in its original size e.g. qvga with remaining area black. From iteration, When i am forcefully sets layout_height/width of Surfaceview in XML, video displayed fine. surface_holder.setFixedSize(w,h) has no effect, neither mp.setdisplay(). Please guide in this. UPDATE XML flie <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android

What is the best way to get an audio file duration in Android?

送分小仙女□ 提交于 2019-11-27 16:17:34
问题 I'm using a SoundPool to play audio clips in my app. All is fine but I need to know when the clip playback has finished. At the moment I track it in my app by obtaining the duration of each clip using a MediaPlayer instance. That works fine but it looks wasteful to load each file twice, just to get the duration. I could roughly calculate the duration myself knowing the length of the file (available from the AssetFileDescriptor) but I'd still need to know the sample rate and the number of

Should a MediaPlayer run in separate thread?

自作多情 提交于 2019-11-27 16:11:30
问题 I'm building an app that streams music from a web server. The app has foreground service that uses a MediaPlayer for playback. My code is based on this example: http://developer.android.com/guide/topics/media/mediaplayer.html In the example, nothing is threaded except the prepareAsync() call. What confuses me is that when I read about the Service class I find this information: "Caution: A service runs in the main thread of its hosting process—the service does not create its own thread and

Playing audio in java using Sun.audio

懵懂的女人 提交于 2019-11-27 15:58:22
I want just to perform a simple task. (I'm a java newbie). I want to play an audio clip when a button is clicked. here's the part of my code(which I did exactly by copying a tutorial from Youtube.) private void btnPlayActionPerformed(java.awt.event.ActionEvent evt) { InputStream in; try{ in=new FileInputStream(new File("C:\\Users\\Matt\\Documents\\dong.wav")); AudioStream timeupsound=new AudioStream(in); AudioPlayer.player.start(timeupsound); } catch(Exception e){ JOptionPane.showMessageDialog(null, e); } } But the problem is, this doesn't work. It throws and IOException saying: "could not

Get cover picture by song

孤街浪徒 提交于 2019-11-27 15:51:11
Is it possible to get a cover picture by song and not by album. Because I have one self combined album with songs and they all have different cover pictures. But when I want to query them I always get the same picture returned. String[] ARG_STRING = {MediaStore.Audio.Media.ALBUM_ID}; ... String albumCover = _cursor.getString(_cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID)); ... MusicUtils.getArtwork(this, -1, Integer.parseInt(albumID)); So i would like to know how it's possible to get an cover image of an song. I know MusicUtils supports getArtwork by SongId, but what ID should I use

How to play a WPF Sound File resource

有些话、适合烂在心里 提交于 2019-11-27 15:49:53
问题 I am trying to play a sound file in my WPF application. Currently I have the following call: private void PlaySound(string uriPath) { Uri uri = new Uri(@"pack://application:,,,/Media/movepoint.wav"); var player = new MediaPlayer(); player.Open(uri); player.Play(); } Now if I specify Media/movepoint.wav as build action Content and load it as a relative or absolute file path it works fine, so I suspect this has something to do with the Pack URI , but I cannot for the life of me figure out what.