Skype-Clone icon indicating copy to clipboard operation
Skype-Clone copied to clipboard

Question: How to add ringtone to incoming call screen

Open alexlovar opened this issue 4 years ago • 10 comments

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?

alexlovar avatar Aug 30 '20 02:08 alexlovar

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();

MaheshPeri19 avatar Sep 07 '20 01:09 MaheshPeri19

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?

Mafazkhan avatar Nov 18 '20 14:11 Mafazkhan

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.

MaheshPeri19 avatar Nov 18 '20 17:11 MaheshPeri19

Hiii can you please give me a hint code I dont get you Im confused

On Wed, Nov 18, 2020, 22:33 MaheshPeri19 [email protected] wrote:

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Ronak99/Skype-Clone/issues/32#issuecomment-729816421, or unsubscribe https://github.com/notifications/unsubscribe-auth/APLFFLUXJJLA7WV37P5QSODSQP46ZANCNFSM4QPK7JTQ .

Mafazkhan avatar Nov 18 '20 19:11 Mafazkhan

Can u please elaborate a little more

On Wed, Nov 18, 2020, 22:33 MaheshPeri19 [email protected] wrote:

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Ronak99/Skype-Clone/issues/32#issuecomment-729816421, or unsubscribe https://github.com/notifications/unsubscribe-auth/APLFFLUXJJLA7WV37P5QSODSQP46ZANCNFSM4QPK7JTQ .

Mafazkhan avatar Nov 18 '20 21:11 Mafazkhan

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
                          : {};
                    }),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

MaheshPeri19 avatar Nov 18 '20 23:11 MaheshPeri19

@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

hasnainsaeed9692 avatar Sep 03 '21 09:09 hasnainsaeed9692

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

MaheshPeri19 avatar Sep 03 '21 09:09 MaheshPeri19

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

hasnainsaeed9692 avatar Sep 03 '21 09:09 hasnainsaeed9692

Sorry. I can't share.

MaheshPeri19 avatar Sep 03 '21 10:09 MaheshPeri19