Home android media player wont play audio file
Reply: 0

android media player wont play audio file

user1593
1#
user1593 Published in June 23, 2018, 4:32 am

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.

You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO