Skip to main content

Posts

Showing posts with the label multimedia example

Read an image from sdcard in Android

To read an image file from sdcard ImageView imageView=(ImageView)findViewById(R.id.imageView1); Bitmap bmp=BitmapFactory.decodeStream(“path of file”); imageView .setImageBitmap(bmp); See more Play audio from sdcard Play video from sdcard How to read text file from sdcard

How to read text file from sdcard in android

Program to read text file from sdcard To read a text file from sdcard, first create an object of FileInputStream class. Set the path of text file in the constructor of FileInputStream. Declare a byte array to read the file. Then call the read method. FileInputStream Fin=new FileInputStream("sdcard/"+s); byte[] b=new byte[100]; t=(TextView)findViewById(R.id.textView1); Fin.read(b); text=new String(b); t.setText(text); Fin.close(); See more Play audio from sdcard Play video from sdcard How to read image from sdcard

Program to play video in android

Play video in android, play video from sdcard  In this example,i'll show you to play video from sdcard  Create object of videoView in your activity VideoView obj=(VideoView)findViewId(R.id.videoView1); Set path of file Obj.setVideoPath(“sdcard/path of file.3gp”); Now call Obj.setMediaController(new MediaController); main.xml <? xml version = "1.0" encoding = "utf-8" ?> < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"     android:orientation = "vertical"     android:layout_width = "fill_parent"     android:layout_height = "fill_parent"     > < TextView       android:layout_width = "fill_parent"     android:layout_height = "wrap_content"     android:text = "@string/hello"     /> < VideoView android:layout_height = "wrap_content" android:id = "@+id/videoView1" android:layout_width = "match_parent" > <

Play audio from sdcard programatically in android

Media Player example in android /how to play audio in android/play song from sdcard programmatically in android The Android multimedia framework includes support for playing variety of common media types, so that you can easily integrate audio, video and images into your applications. You can play audio or video from media files stored in your application's resources (raw resources), from standalone files in the filesystem, or from a data stream arriving over a network connection, all using   MediaPlayer APIs. In  this example, I’ll show you a simple program to play an audio file from sdcard. To play an audio file, first create an object of media player class MediaPlayer mp3=new MediaPlayer(); Then set path of file Mp3.setDataSource(“sdcard/filename.mp3”); Before playing audio, call prepare Mp3.prepare(); To play audio ,call Mp3.start(); To pause, call Mp3.pause To stop audio, call Mp3.stop();   main.xml <? xml version = "1.0" encoding = "utf-8" ?> &