media-player

How do I play an mp3 in the res/raw folder of my android app?

余生长醉 提交于 2019-11-26 22:32:36
I have a small (200kb) mp3 in the res/raw folder of my android app. I am trying to run it in an emulator from Eclipse. It is recognized as a resource in the R file but when I try to prepare/start, my activity crashes! Was there something else I needed to change, perhaps in the manifest? MediaPlayer mPlayer = MediaPlayer.create(FakeCallScreen.this, R.raw.mysoundfile); try { mPlayer.prepare(); mPlayer.start(); } catch (IOException e) { // handle this later } When starting the activity i.e on onCreate put the following code. public void onCreate(Bundle savedInstanceState) { super.onCreate

How do I use Android ProgressBar in determinate mode?

戏子无情 提交于 2019-11-26 22:08:28
I am writing a media player and i would like to have a progress bar showing the progress of the song. I found the ProgressBar class, but all i can get on the screen is a circular spinning icon. what im looking for is an actual bar. How do i change the style of the ProgressBar to be a bar (not a circle) and how would i use it with MediaPlayer? thanks use the style ?android:attr/progressBarStyleHorizontal for example: <ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyleHorizontal" and this is an example with MediaPlayer: package com.playerpgbar; import android.app

android video, hear sound but no video

雨燕双飞 提交于 2019-11-26 22:02:59
问题 I have tried several different examples but I cannot get any video to show. I hear sound but no video. I thought maybe I just had a incorrect video format so I downloaded a fiat commercial in 3gp format and still no joy. I am using the Eclipse Java EE with android sdk and my app targets the 1.5 sdk (Api Level 3) without google api. Could someone please post a link to a video known to play in android or point out my problem with the code. I have tried all I could think of .. with/without

How to detect if another audio is playing in background? (Windows Phone 7)

你说的曾经没有我的故事 提交于 2019-11-26 21:49:20
问题 One of my apps have recently failed certification because: "my app stops background music without asking user when it wants to play some music". Now the question is: how can we detect if there is any music playing in the background? Regards 回答1: using Microsoft.Xna.Framework.Media; ... if (Microsoft.Xna.Framework.Media.MediaPlayer.State == MediaState.Playing) { .... } 回答2: You need to examine the MediaPlayer.GameHasControl property. http://msdn.microsoft.com/en-us/library/microsoft.xna

java wav player adding pause and continue

时光总嘲笑我的痴心妄想 提交于 2019-11-26 21:45:26
问题 I have this code which plays wav files from a folder with play and stop. How can I add pause and continue? import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.applet.AudioClip; import java.net.URL; public class JukeBox extends JFrame { private JComboBox musicCombo; private JButton stopButton, playButton; private AudioClip[] music; private AudioClip current; public JukeBox(String title) { super(title); getContentPane().add(new

Playing Audio with J2ME

。_饼干妹妹 提交于 2019-11-26 21:24:26
问题 What is the best way to play audio utilzing the J2ME Media libary? For example, should I make use of the MMAPI or should I just use the Midlet's platformRequest(String s) method? 回答1: The following code should work for 90-95% of handsets out there that support JSR-135. Ordering of all the various method calls is key for this to be portable. This is for sounds local to your JAR. Any streamed audio would be another problem altogether :) // loads the InputStream for the sound InputStream

MediaPlayer stop playing after about 5 seconds

和自甴很熟 提交于 2019-11-26 20:57:54
问题 I'm currently developing a simple game and now it's time to add music and sound effect. I tried using MediaPlayer , just like described here: Android media player bug However I have another problem, the MediaPlayer stop playing the music after about 5 seconds. What is probable causing this? 回答1: I had this problem too. It was probably due to having the MediaPlayer-object only existing within a method. For example: //ERROR, stops after 5 sec! public static void playMusic(int id) { MediaPlayer

MediaPlayer.setDataSource causes IOException for valid file

你。 提交于 2019-11-26 20:52:43
This code used to work. Then, maybe I changed something, somewhere (or if I know Android right, an update introduced a bug in the media player). It stopped working on some devices! Especially my Nexus S (2.3.6). The file test.m4a (17 775 201 bytes) was downloaded by the app. To verify its integrity, I copied it to the SD and played it on my PC. No problem! Also binary-compared it with the original file, and it matched 100%. try { _mediaPlayer = new MediaPlayer(); _mediaPlayer.setOnCompletionListener(this); _mediaPlayer.setOnPreparedListener(this); _mediaPlayer.setOnSeekCompleteListener(this);

Listener (or handler) for video finish

青春壹個敷衍的年華 提交于 2019-11-26 20:47:52
问题 I have implement the following code in order to test playing a video from a remote web server through it´s URL. videoView = (VideoView)this.findViewById(R.id.videoView); MediaController mc = new MediaController(this); videoView.setMediaController(mc); videoView.setVideoURI(Uri.parse("http://sayedhashimi.com/downloads/android/movie.mp4")); videoView.requestFocus(); The code is working just fine, even in the Android emulator. I just would like to know if there's any listener (or handler) to

Exception when calling setDataSource(FileDescriptor) method (failed.: status=0x80000000)

核能气质少年 提交于 2019-11-26 20:20:22
问题 I'm developing a video streaming application and I'm getting stuck when calling set setDataSource with a FileDescriptor. I want my application to play the video as it is being downloaded, so once I get a minimum number of bytes, I move those bytes to another file so it can be played in another file while it's being downloaded in the original file. So, I check if I can start the media palyer every packet like this: if (mediaPlayer == null) { // Only create the MediaPlayer once we have the