Android Video Streaming (VideoView) Tutorial

  • dillu

    There is no need of using AsyncTask in this example.

    • Hi Dillu, thanks for your advise. I will make the necessary changes in the future. Happy coding. 🙂

  • theunseen

    Thanks for this Tutorial. Iam a “Android Beginner”, so i think my questien is quiet simple for you Is it possible, to start the example video with a button or a click?

  • tuan

    Waiting for detail tutorial about Media streaming, such as play a movie : play, pause, onBufferingUpdate, onSeekCompletion, … when a movie is a long video.
    God bless you. Many thanks.

  • dhanuell

    Thanks for this Tutorial. I have a question.. why my app doesn’t show the controll like pause, prev, and next? thanks in advance

    • dhanuell

      sorry, just my fault.. to show the control, just hit search button on AVD XD
      Many thanks.

      • Hi dhanuelle, I’m glad you figure it out yourself. 🙂

  • Kutalp*DH

    hey i want to add more videos maybe 20 -30 what should i do?

    • Hi Kutalp, I’ll work out a listview for you soon. Stay tuned. 🙂

      • Kutalp*DH

        Thanks! Waiting for you! 🙂 Mail me for oyur new work ok? 🙂

  • Achiik Jerr

    i haf problem here


    it say “R cannot be resolve to a variable”

    • Hi Archiik, please ask your questions in our Android Developers Forum. 🙂

    • Dhasneem

      I’m also having the same problem

      • josi

        This might help for those who are still cannot resolve the problme. Source: . Read the following: is a file that the Android Eclipse plugins creates while building your application. is created under the “gen” directory. This file is generated from the information in the “res” directory. If you run select “Project” -> “Clean…” on the Eclipse menu, it will remove and then regenerate the R.javafile.

        The problem “R cannot be resolved” happens when you change your package name in the AndroidManifest.xml file. It uses your Android package name to create a subdirectory under the “gen” directory where it stores the file.

        Eclipse may have problems executing clean, because it is confused about where the file is when you have changed the Android package name. You can either rename the subdirectory under gen to match your new package name, or you can change your package name back to the old name. Do the clean and then change the package name to the new name you want. This works best if you stop Eclipse from trying to build while you are changing the package name. Under the “Project” menu uncheck the option to “Build Automatically” and also when the “Clean…” dialog asks if it should “Start a build immediately” uncheck the box so it doesn’t try to build while you are changing the package name. After you have changed the name you can turn “Build Automatically” back on again.

        Note that if your AndroidManifest.xml file package name does not match your Java package name, Eclipse will end up automatically adding an “import .R;” line in all your .java files that have any references to R. If you change your AndroidManifest.xml package name, sometimes Eclipse does not update all of these added imports. If that happens, use the Eclipse refactoring (ALT + Shift + R) to change the import statement in one of your Java files to your new AndroidManifest.xml package name. It is best to do this while you have disabled “Build Automatically”.

  • Kutalp*DH

    Hey how can i add 10-20 videos how can i add ( i am kutalp )


    hİ, thanks for this tutorial.I have a question.I want do mjpeg streaming that how can I do?.For IP camera…

  • Meenu

    Hi , How can i do mjpeg streaming with ip camera

  • vivekanandhan

    Thanks for the tutorial, Is there any possibilities to stream YUV video format..?? Please help me, thanks in advance.

  • Sangeetha

    Hi how can i detect when there is no response from the server i.e the given video url

  • Sivaram

    Hi, how to stream video from dynamic links?

  • Yamen Imad Nassif

    Is there any way to turn that URL
    into another android cam
    like making another android device streams the video on its ip so i can play it like you did

  • Kasun Max

    thank you for this tutorial it is really helpful to me
    Thanks (y)

  • SofiaEO

    Can someone help me get more compatible videos ? Or how/where can I get them ? please S.O.S.

    • you need some tools to get these videos. Try this

      • SofiaEO

        You’re suggesting I should download the video on my computer. This isn’t what I asked for actually. If you read through the code it’s a LINK via the WWW that I need not a path.

        • This link is a video I get from the Internet and uploaded into my server. Hope I answered your question. 🙂

          • SofiaEO

            I tried something; downloaded the video, after conversion, in .3gp format and uploaded it but it didn’t work…

          • SofiaEO

            I tried something; downloaded the video, after conversion, in .3gp format and uploaded it on youtube but it didn’t work…

          • You must make sure the link is accessible directly. Try uploading into dropbox and create a public link. Then use that public link.

          • Guest

            I did what you stated above but I’m still getting the same error : ‘Can’t Play this video.’ I’m uploading the error lines in the log :

          • SofiaEO

            FW :
            Here’s the link to my tryout video :
            I did what you stated above but I’m still getting the same error : ‘Can’t Play this video.’ I’m uploading the error lines in the log :

          • SofiaEO

            Uhmm.. I changed www to dl , for a second I thought it worked since I got that black screen (of the player) but shortly after I got the same dialog box saying “Can’t Play This Video” ;

            PS : Sorry for this inconvenience 🙁 and thank you for your help !

          • hm. Try shorten the filename. Let me know if it works. 🙂

          • SofiaEO

            I ended up with this :
            BUT it still hasn’t worked 🙁

          • SofiaEO

            I figured out the problem ; the length of the video. I just tried a commercial video (30s) and it worked. Thank you for your time Sir.

          • Flovek Khan

            add internet permision

      • marco calle

        The same problem “Can’t play video”, whay happend?

  • Ravi Kumar Meena

    Please help me to find the solution to perform the Resize and Zoom functionality on video player by clicking on button in Android. Please give me a demo of that solution..

  • Ekrem yılmaz

    Please,can you share a tutorial, about IP Camera stream,
    How we get stream from IP camera simply?

  • Raheel Shah

    I have Issue in this I have download your tutorial but when I run it in my phone I shows error can not play this video .

    • Guest

      when I import this project in my Eclipse it shows this error in Eclips

    • Syed Zulfiqar Ali

      all you need to do is just add the perditions of WALK_LOCK and INTERNET then your stream will work fine

  • seetha

    Thank you so saved my day

  • saeed

    How i can play m3u play list

  • Na

    Hi, thank you very much. Really helpful. But I got a problem when playing video. There is no audio at all, just the video. Could you help me to figure it out?

  • Nav Singh

    very nice toturial helped a lot.. also please visit my site for android and technology related help –

  • Idris Bohra

    Hi, thank you so much for the code. from last 3 hour i m searching for this type of code and finally using your code my problem is resolved. Thanks again.

  • guys want to create a video view on which i can play two videos at once not a single video any one can help me out in this plz 🙂 i have seen many codes but they tell how to play one single video not two with next functionality … any one can help contact me on my email

    • Devendra Vaja

      You need to look for the fragments. The source can be reused. Fragments can be seen as two different activities running on the same screen. Although they have different life cycle than Activity.

      • can u provide me an example with code as i m so new ,,, thanks

        • Devendra Vaja

          Ok. Give me sometime. I will come back with the good example.

          • Ok buddy i m waiting 🙂

          • Devendra Vaja

            Hi Murtaza, I could finish the demo to play two videos at the same time. Please refer to the complete Android Studio source code here :

            In case you are working with the Eclipse IDE with ADT plug-in the files of your interest are:
   & : /app/src/main/java/example/vaja/devendra/ganesha/twovideos

            Resource files are located at /app/src/main/res

            In a way “main” folder is of use to you in case not using the Android Studio

            Hope it helps.

          • But i wanted one video to be shown on a page then user click on next to play next video like this way i want to store more then 10 videos…

          • Devendra Vaja

            That is really easy…
            A) add a button below the videoview of the given tutorial
            B) handle the onclick event and start the videoview activity by sending intent to the same activity.
            C) call finish() after that.
            D) use Intent bundle to send video file name to the activity.

          • again can u code that please 🙂

          • Devendra Vaja

            Sorry Murtaza, I suggest you start learning the basics and do that of your own. I am here to help in case of issue only. Do try the steps of your own and do revert back incase of any issue.

          • Thank you buddy 🙂

          • Raza Abid Abbasi

            i am getting error ‘can’t play video’ while playing any video from online source in video view, i am tired help me plz…………..

    • Akhil Chandran

      Why dont you try adding two video views fro playing two videos?!

  • JongWoo Choi

    hi, I want to play ip Camera view on the wifi board(rtsp server, Nuvoton N3292) through Wifi connection. Your code and my simple code, videoview, are well working when they are playing a movie clip and internet, but both codes can’t get the camera image from the board.

    below is the code and error msg. plz help me. thanks.

    • Diógenes Ricardo

      Did you get?

      • JongWoo Choi

        No, I can’t solve this problem. Do you know this problem?

        • Diógenes Ricardo

          I’m trying too.

  • Vikash

    This is not working with .stream file.

  • Ayaan Muhammad

    how we can stream audio..lfor Any radio station

    • Richard Barcelos

      Hello managed to convey radio?

      I am rpocura this solution also

      my email is

  • Victor Vidal

    hello I need help, I want transmit live video, anyone know how?
    my email is
    @ayaanmuhammad:disqus @murtazapanhwar:disqus @disqus_TEv9Ti71bR:disqus @jongwoochoi:disqus @disqus_9qN8d3my6F:disqus

  • Study M

    I am new to write program.

    After I download u source code to my eclipse, I got the following and don’t know how to solve them. Pls. give me some help.

    the apk file work well when I download it to my mobile. But just don’t understand why the above happen.

    Thx very much for you help!

  • Study M

    I got this error on the first line of code. What does it mean, and how to solve it?
    Multiple markers at this line

    – The type java.lang.Object cannot be resolved. It is indirectly referenced from

    required .class files

    – The type java.lang.String cannot be resolved. It is indirectly referenced from

    required .class files

  • sai

    code working well

  • Bijesh Shrestha

    for longer videos, how to show progress dialog when video pauses and buffers in the middle?

  • PrakashK Gowin

    It works well with already recorded video, But I want to stream live video from web (“”) to android device. I checked with the above url, it says “Can’t play this video” error. I had gone through that http will not support live stream, but rtsp will do, Is there any way to get the live stream on android? Hope to get some suggestions 🙂 Thanks

    • Random User

      hey did you ever figure it out? Im trying to stream my foscam camera in android studio

  • harsh chudasama

    i want to stream from a webcam,

    right now streaming of webcam is displaying on webpage i.e

    what should i do in your code by which i can stream from this address to android app?

    in your code i did something like this

    String VideoURL = “”;

    but it couldnt play video stream


    Thx very much. Need to stream live video from web !

  • swapnil dhake

    I tried to run the above code but throws error “Can’t play this video”. can you please help.

  • Erum Hannan

    i m gettting this error :

    beginning of crash

    07-25 13:10:45.708 16498-16498/com.sample.samplevideoview E/AndroidRuntime: FATAL EXCEPTION: main

    Process: com.sample.samplevideoview, PID: 16498

    android.view.WindowManager$BadTokenException: Unable to add window — token null is not valid; is your activity running?

    at android.view.ViewRootImpl.setView(

    at android.view.WindowManagerGlobal.addView(

    at android.view.WindowManagerImpl.addView(



    at android.widget.VideoView$2.onPrepared(


    at android.os.Handler.dispatchMessage(

    at android.os.Looper.loop(


    at java.lang.reflect.Method.invoke(Native Method)



    07-25 13:10:45.929 16498-16524/com.sample.samplevideoview W/MediaPlayer: info/warning (703, 0)

    07-25 13:10:45.929 16498-16524/com.sample.samplevideoview W/MediaPlayer: info/warning (701, 0)

    07-25 13:10:46.929 16498-16510/com.sample.samplevideoview W/MediaPlayer: info/warning (703, 0)

    07-25 13:10:46.929 16498-16510/com.sample.samplevideoview W/MediaPlayer: info/warning (702, 0)

    07-25 13:10:46.931 16498-16509/com.sample.samplevideoview W/MediaPlayer: info/warning (3, 0)

    07-25 13:10:56.323 16498-16510/com.sample.samplevideoview E/MediaPlayer: error (1, -19)

    07-25 13:10:56.324 16498-16524/com.sample.samplevideoview E/MediaPlayer: error (1, -38)

  • Shiva Singhal

    is there any way we can chnage the quality of video in android while bufferring

  • Pop Adrian

    Hello 🙂 ! Please help me, if you have disponibility. I don’t know how i can to put an IP camera, and how i can watch live from this ip camera (D-link 930L ). This tutorial is brilliant, it works very well, thanks a lot!

  • Hang Nadi

    it stretced for portrait video. how could you solve it?

  • Ranjitha N

    How play video along with downloading..(Like you tube buffering play video)

  • Jainam Jhaveri

    Can we seek the online video ? I tried to stream one and videoView.canSeekForward() returns false.

  • RaluG

    This is all really helpful!

    However, if you are having trouble manually coding or you have no idea whatsoever on how to code, I know a few alternatives that can help! Of course, one of them is, in my opinion, the best! I am talking about the live video streaming library for Android, provided by Streamaxia ( and about their app made especially for easy live streaming:

    I hope this helps some of you!