Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to add ringtone to incoming call screen #32

Open
alexlovar opened this issue Aug 30, 2020 · 10 comments
Open

Question: How to add ringtone to incoming call screen #32

alexlovar opened this issue Aug 30, 2020 · 10 comments

Comments

@alexlovar
Copy link

hello, the app is working only video call, the incoming call screen is showed when a video call is receive but there is not sound, how to add a ring tone to incoming call screen?

@MaheshPeri19
Copy link

I used below package
Add this package in yaml file : flutter_ringtone_player: ^2.0.0

And added below code.

@OverRide
void initState() {
super.initState();
// Start ringtone.
FlutterRingtonePlayer.playRingtone();
}

Call stop ringtone method in call accept button & call end button and also dispose method.
// Stop Ringtone
FlutterRingtonePlayer.stop();

@Mafazkhan
Copy link

I used below package
Add this package in yaml file : flutter_ringtone_player: ^2.0.0

And added below code.

@OverRide
void initState() {
super.initState();
// Start ringtone.
FlutterRingtonePlayer.playRingtone();
}

Call stop ringtone method in call accept button & call end button and also dispose method.
// Stop Ringtone
FlutterRingtonePlayer.stop();

where do I add this code in which file or tell me where u added this and did it work for u?

@MaheshPeri19
Copy link

MaheshPeri19 commented Nov 18, 2020

Yes, it worked for me. I have added this in incoming call screen (pickup screen) where accept reject button appear.

Example : User A make the call to User B. Then User B gets the incoming call with accept/reject buttons. When ever User B gets incoming call, i am calling start method of ringtone. When he clicks accept or reject button, i am stopping the ringtone by calling stop method.

My Scenario :

I am using this sample project, so that in PickupScreen initstate method, i am calling FlutterRingtonePlayer.playRingtone();
Then when user accept or reject, i am calling FlutterRingtonePlayer.stop();

PickupScreen class will execute whenever current user gets incoming call. So it works.

Note : this ringtone code is required only when the app is in foreground or running state. For background or closed or killed state, this is not required as must use callkeep package or callkit package.

@Mafazkhan
Copy link

Mafazkhan commented Nov 18, 2020 via email

@Mafazkhan
Copy link

Mafazkhan commented Nov 18, 2020 via email

@MaheshPeri19
Copy link

MaheshPeri19 commented Nov 18, 2020

The same code which exists in sample. I have added ringtone start and stop methods. If this sample project (Ronak99
/Skype-Clone) is working for you, nothing new to change. I have added only ringtone methods in between. First try to run this sample project in two devices or two simulators. Then you will get it.

class PickupScreen extends StatefulWidget {
  final Call call;

  PickupScreen({
    @required this.call,
  });

  @override
  _PickupScreenState createState() => _PickupScreenState();
}

class _PickupScreenState extends State<PickupScreen> {
  final CallMethods callMethods = CallMethods();

  bool isCallMissed = true;

  addToLocalStorage({@required String callStatus}) {
    Log log = Log(
      callerName: widget.call.callerName,
      callerPic: widget.call.callerPic,
      receiverName: widget.call.receiverName,
      receiverPic: widget.call.receiverPic,
      timestamp: DateTime.now().toString(),
      callStatus: callStatus,
    );

    LogRepository.addLogs(log);
  }

  @override
  void dispose() {
    if (isCallMissed) {
      addToLocalStorage(callStatus: kFirebaseMissedCallKey);
      print("======= dispose/pickupscreen ========= ");
      // Stop Ringtone
      FlutterRingtonePlayer.stop();
    }
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
    // Start ringtone.
    FlutterRingtonePlayer.playRingtone();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: kWhiteColor,
      body: Container(
        alignment: Alignment.center,
        padding: EdgeInsets.symmetric(vertical: 100),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              "Incoming Call...",
              style: TextStyle(
                fontSize: 30,
              ),
            ),
            SizedBox(height: 50),
            CachedImage(
              widget.call.callerPic,
              isRound: true,
              radius: 180,
            ),
            SizedBox(height: 15),
            Text(
              widget.call.callerName,
              style: TextStyle(
                fontWeight: FontWeight.bold,
                fontSize: 20,
              ),
            ),
            SizedBox(height: 75),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                IconButton(
                  icon: Icon(
                    Icons.call_end,
                    size: 30,
                  ),
                  color: kPrimaryColor,
                  onPressed: () async {
                    // stop ringtone.
                    FlutterRingtonePlayer.stop();

                    isCallMissed = false;
                    addToLocalStorage(
                        callStatus: kFirebaseReceivedCallKey);
                    await callMethods.endCall(call: widget.call);
                  },
                ),
                SizedBox(width: 25),
                IconButton(
                    icon: Icon(
                      Icons.call,
                      size: 30,
                    ),
                    color: kGreenColor,
                    onPressed: () async {
                      // stop ringtone.
                      FlutterRingtonePlayer.stop();
                      isCallMissed = false;
                      addToLocalStorage(
                          callStatus: kFirebaseReceivedCallKey);
                      await Permissions.cameraAndMicrophonePermissionsGranted()
                          ? Navigator.push(
                              context,
                              MaterialPageRoute(
                                builder: (context) =>
                                    CallScreen(call: widget.call),
                              ),
                            )
                          // ignore: unnecessary_statements
                          : {};
                    }),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

@hasnainsaeed9692
Copy link

@MaheshPeri19 Did you implement the calling screen when the app is closed or fone is locked? I badly need to implement this. Please help or share some code if you have implement it.
Thanks

@MaheshPeri19
Copy link

No.
At the time of implementing this skype clone, it is working in only app is in active state, not in background or locked state.

If you are looking for custom incoming call like whatsapp and skype for Android only, then look into below link

https://github.com/rafaelsetragni/awesome_notifications/issues/35#issuecomment-751431492

@hasnainsaeed9692
Copy link

@MaheshPeri19 Can you share your project if it's possible?

@MaheshPeri19
Copy link

Sorry. I can't share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants