Home android media player wont play audio file
Reply: 0

android media player wont play audio file

user4917
1#
user4917 Published in September 20, 2018, 12:45 pm

im making a music app just for fun. I can read all my music files from sd card but MediaPlayer wont play the sound. I have the path to the file which i pass to the media player with setDataSource but nothing happens and i get no exceptions. Here is the code im using.

Uri songUri;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_player);
        setUpViews();
        MediaPlayer mp = new MediaPlayer();

        try {
            mp.setDataSource(songUri.toString());
            mp.prepare();

        } catch (IllegalArgumentException e) {
            Toast.makeText(this, "ILLEGAL ARGUMENT EXCEPTION", Toast.LENGTH_LONG).show();
            e.printStackTrace();
        } catch (SecurityException e) {
            Toast.makeText(this, "SECURITY EXCEPTION", Toast.LENGTH_LONG).show();
            e.printStackTrace();
        } catch (IllegalStateException e) {
            Toast.makeText(this, "ILLEGAL STATE EXCEPTION", Toast.LENGTH_LONG).show();
            e.printStackTrace();
        } catch (IOException e) {
            Toast.makeText(this, "IO EXCEPTION", Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }
          mp.start();
          Log.d("URI AFTER SET UP", songUri.toString());
    }

As i said before nothing happens when i open this activity but i still get all the Log.d in the console. Is there any more configurations for the media player to play the music? Thanks in advance.

share|improve this question

4 Answers 4

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.360018 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO