0

I know this would be a dumb question. but I am new to learning java.

This is my VideoList_F.java:- https://www.codepile.net/pile/K8BdKJyP

Home_F.java:- https://www.codepile.net/pile/NJ0PpaJ7

enter image description here

In above picture exoplyer.setPlayWhenReady(false) or exoplyer.setPlayWhenReady(true) are used for play or pause player.

I want to pause play by using exoplyer.setPlayWhenReady(false) in Home_F.java

I want to do something like this. If anyone can give hint on how to solve this??

enter image description here

sanket kheni
  • 1,482
  • 2
  • 12
  • 29
  • 5
    if you are new to learning java, you should be learning the basics of java, not trying to write android apps. That being said, you can add a getter in your other class, that is if there is a link between the first and the second class (composition). Show your code here (don't link to it) and show it as formatted code, not images – Stultuske May 19 '21 at 06:23
  • I added full code on the code pile.. – sanket kheni May 19 '21 at 06:24
  • add it as formatted code in the question, don't add links to external sources – Stultuske May 19 '21 at 06:25
  • Stackoverflow is not allowing to add more than 50 lines.. – sanket kheni May 19 '21 at 06:26
  • Bro I searched on google but not found appropriate answers for my specific problem – sanket kheni May 19 '21 at 06:27
  • Codes can be added up to any number of lines. Don't worry. – Samudra Ganguly May 19 '21 at 06:27
  • code has 1260 lines.. – sanket kheni May 19 '21 at 06:28
  • 4
    @sanketkheni if you need that many lines to show your problem, you really should start learning the basics. – Stultuske May 19 '21 at 06:29
  • I just want to solve just 1 problem. learning full java for that is not appropriate. If anyone can give just a little hint on how to do that I will find it on google. – sanket kheni May 19 '21 at 06:31
  • @sanketkheni I already have. ignoring it won't change the answer. is there a link between the two classes? Is that variable an instance or a class variable? Ignoring responses won't help you to fix your issue faster. yes, you want to solve just one problem. Learning full java isn't appropriate? It would have been appropriate to do before starting to write this code in the first place. – Stultuske May 19 '21 at 06:34
  • I think this is what you want , to communicate between fragments It has been aswered already : [Basic communication between two fragments](https://stackoverflow.com/questions/13700798/basic-communication-between-two-fragments) – kelvin May 19 '21 at 06:53
  • Your development speed would be much faster if you first learnt java and then started android. "earning full java for that is not appropriate. " is not what a good dev would say – lyncx May 19 '21 at 06:57
  • Please read [no pictures of exceptions](http://idownvotedbecau.se/imageofanexception/) / [no pictures of code](http://idownvotedbecau.se/imageofcode). Then use the [edit] link to replace screen shots of text with nicely formatted/indented text within your question. – GhostCat May 19 '21 at 07:06
  • And for sure you can add more than 50 lines of code, if you just have also enough text coming with it. Beyond that, the idea is that you put up a [mcve]. You dont give us ALL your code, but just the relevant parts. As nicely formatted text, not images, not as links to some 3rd party service. And I agree: before you engage with Android, consider learning base java for a few weeks, you arent doing yourself a favor. – GhostCat May 19 '21 at 07:08
  • **I just want to solve just 1 problem.** Sorry, when you dont understand what you are doing, then solving 1 problem means ... making 1 step forward, to then be blocked again. Rest assured: when you lack basic knowledge, **every** step you are going to take has the potential to be hard and frustrating. – GhostCat May 19 '21 at 07:10

1 Answers1

1

For controlling the exoplayer from the Home_F.java,

First Create a method similar to below in VideoList_F class

public void setExoPlayWhenReady(boolean playWhenReady){
    exoPlayer.setPlayWhenReady(playWhenReady);
}

you need to have an interface defined as below in Home_F class

private Home_F_Listener homeFListener = null;

interface Home_F_Listener {
    public void setPlayWhenReady(boolean playWhenReady);
}

Then in the onAttach overrides method of Home_F fragment, extract the instance of Home_F_Listener from the context

if(context instanceof Home_F_Listener){
    homeFListener = (Home_F_Listener) context ;
}

Then call the interface method from the Home_F class when required as below

if(homeFListener != null){
    homeFListener.setPlayWhenReady(false)
}

Then implement the interface in the parent activity where that fragment is inflated. Also your parent activity should hold the instance of the VideoList_F fragment.

    public class ParentActivity extends Activity implements Home_F_Listener {
//other code
@Override
public void setPlayWhenReady(boolean playWhenReady){
    videoList.setExoPlayWhenReady(playWhenReady);
}
//other code
}

Ankit Wala
  • 122
  • 9
  • Non-static method 'setExoPlayWhenReady(boolean)' cannot be referenced from a static context – sanket kheni May 19 '21 at 07:14
  • @sanketkheni that line doesn't cause that. it can't cause that, since videoList is supposed to be an instance. – Stultuske May 19 '21 at 07:18
  • @stultuske as I saw the complete code, both these classes are fragment, so he will have to create a interface in Home_F which the parent activity implements and then call VideoList method from that activity. Will update my answer in some time – Ankit Wala May 19 '21 at 07:21
  • I created an instance of an class `videoList=new VideosList_F();` and tried `videoList.setExoPlayWhenReady(false);` – sanket kheni May 19 '21 at 07:28
  • but not working.. – sanket kheni May 19 '21 at 07:28
  • @sanketkheni probably because it isn't the same instance. Do you understand why this has an impact? – Stultuske May 19 '21 at 07:29
  • no.What about AnkitWala 's answer.About creating interface – sanket kheni May 19 '21 at 07:33
  • @sanketkheni you're just setting yourself up for a bigger fall. if you create an interface, you'll still have to use the (correct) instances. Since you're not familiar with instances, you're likely to get that wrong as well. – Stultuske May 19 '21 at 07:42
  • Bro can you add an answer..I would be a big help for me. – sanket kheni May 19 '21 at 07:42
  • @sanketkheni one that you would understand? No. seriously, you need to learn the basics. – Stultuske May 19 '21 at 07:43
  • Yes, But if you know how to solve please add an answer. I do not want to understand the answer. I just want to solve the problem. – sanket kheni May 19 '21 at 07:44
  • @sanketkheni this question is closed, so even if I wanted, I couldn't add an answer. I already added al you needed to know in the first comment. Yes, if you want it to solve your issue, you NEED to understand that. – Stultuske May 19 '21 at 07:47