Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: The video starts to play when the application run. How to avoid this?

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default The video starts to play when the application run. How to avoid this?

    I made a listview with a videoview. When the application is running, the video starts automatically playing. I don't want that. The video should start playing when I click on it. I made an Adapter.

    ArrayAdapter

     
    MediaController mc;
     
    public View getView(int position, View convertView, ViewGroup parent) {
     
            LayoutInflater LayoutInflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     
            View listViewItem = LayoutInflater.inflate(R.layout.symptomlistitem, parent, false);
            TextView txtSymptom = (TextView)listViewItem.findViewById(R.id.txtSymptom);
            VideoView videoSymptom = (VideoView) listViewItem.findViewById(R.id.videoSymptom);
     
            Symptom symptom = this.getItem(position);
     
            txtSymptom.setText(symptom.getSymptom());
            videoSymptom.setVideoURI(Uri.parse("android.resource://com.example.speechrecogniser/" + (symptom.getVideo())));
            videoSymptom.setVisibility(View.VISIBLE);
            videoSymptom.setMediaController(mc);
            mc.setAnchorView(videoSymptom);
            videoSymptom.start();
            return listViewItem;
        }

    I've added the MediaController, but it didn't work. Can anyone help me please?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: The video starts to play when the application run. How to avoid this?

    What environment does this code run in? It looks like Android.

    What causes the method that shows he video to be called?
    Can the code that shows the video be moved to where it is only called when desired?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: The video starts to play when the application run. How to avoid this?

    Yes, in Android Studio.

    I don't know

    Maybe I shouldn't start the video in the adapter? But where should I start it?

    --- Update ---

    I have this function on the SymptomsActivity

     
    public void clickOnList(){
            ListView lstSymptoms = (ListView)findViewById(R.id.lstSymptoms);
     
     
            lstSymptoms.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Symptom selectedSymptom = (Symptom)parent.getItemAtPosition(position);
                    Log.d("Name", selectedSymptom.getSymptom());
     
                    videoSymptom.setMediaController(mc);
                    mc.setAnchorView(videoSymptom);
                    videoSymptom.start();
                }
            });
        }

    Maybe I have to set it here? :/

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: The video starts to play when the application run. How to avoid this?

    Did you try it? What happened?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Unable to play video in JPanel using vlcj in ubuntu 13.04
    By Vabhi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 15th, 2014, 01:09 PM
  2. how to play audio in a stand alone application
    By james12 in forum AWT / Java Swing
    Replies: 3
    Last Post: July 2nd, 2014, 05:01 AM
  3. Add online video to web application ,Receives sms
    By vinod112331@gmail.com in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 6th, 2013, 11:04 PM
  4. Problem is trying to play a video from Webcam using JMF
    By srinithegr8 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 13th, 2013, 11:42 AM