Play mp3 and view image from assests folder java

public void download(MenuItem item) throws IOException { AssetFileDescriptor afd = getAssets().openFd("ape.mp3"); MediaPlayer player = new MediaPlayer(); player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); player.prepare(); player.start(); InputStream ims = getAssets().open("ape.png"); // load image as Drawable Drawable d = Drawable.createFromStream(ims, null); // set image to ImageView ImageView mImage; setContentView(R.layout.activity_main); mImage = (ImageView)findViewById(R.id.imageView); mImage.setImageDrawable(d); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.