how to play a MP3

All your problems with Audio, Video and Images.

how to play a MP3

Postby lord_ure » Wed Apr 21, 2010 3:02 am

Hi everybody. In my activity I need to play a MP3 file and I have found on this forum the tutorials from plusminus but it doesn't work with me. What's more I have tried to solve all my problem looking for solutions on internet but no way.
So I'd like to have one of your own code, just to play a MP3, without options, and the way you set the mp3 file in your project, because I'm lost and I need to submit my project next week.
I code under netbeans.

++ 8)

PS: Sorry about my english but I'm french XD.
lord_ure
Developer
Developer
 
Posts: 46
Joined: Fri Apr 16, 2010 4:29 pm
Location: Nancy, FRANCE

Top

Postby hkswaroop » Tue Apr 27, 2010 2:06 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.swa.test;
  3.  
  4.  
  5.  
  6.  
  7.  
  8. public class test extends Activity {
  9.  
  10.     Button b;
  11.  
  12.     MediaPlayer MPX ;
  13.  
  14.     @Override
  15.  
  16.     public void onCreate(Bundle savedInstanceState) {
  17.  
  18.         super.onCreate(savedInstanceState);
  19.  
  20.         setContentView(R.layout.main);
  21.  
  22.         b=(Button) findViewById(R.id.Button01);
  23.  
  24.         MPX = MediaPlayer.create(test.this, R.raw.a);
  25.  
  26.         b.setOnClickListener(new OnClickListener() {
  27.  
  28.                        
  29.  
  30.                         @Override
  31.  
  32.                         public void onClick(View v) {
  33.  
  34.                                                                
  35.  
  36.                 try {                  
  37.  
  38.                     MPX.start();                    
  39.  
  40.                 } catch (Exception e) {
  41.  
  42.                     e.printStackTrace();
  43.  
  44.                 }
  45.  
  46.                         }
  47.  
  48.                 });
  49.  
  50.     }
  51.  
  52. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
hkswaroop
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed May 20, 2009 8:15 am
Location: Bangalore

Postby lord_ure » Tue Apr 27, 2010 7:10 pm

Hi, and thanks for answering to my problem I have copy your code to a new project and I have runned it. I don't know why I still have the same problem, I have a resource$notfound exception when I call create even if my mp3 is in my raw folder and my variable R.raw.a exists. It is very strange. Do you have any idea ?

++
lord_ure
Developer
Developer
 
Posts: 46
Joined: Fri Apr 16, 2010 4:29 pm
Location: Nancy, FRANCE

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google [Bot] and 13 guests