I think Alarm Manager is your solution.
The flow would be the following:
- Android app opens and request the server what the server time is and when is the next video.
- Calculate how in how many minute or seconds the time will be done.
- Setup an alarm in the device for that time. Let's say the server time is 8:45 and the next video is at 9:30. So you know 45 minutes has to pass in order to be able to play the video. So the alarm should be trigger in 45 minutes.
- When the alarm is trigger, check the server again and if it's fine, play the video and schedule your next alarm (for the next video or if the server now wants to play the video in another moment), if the user fake his time, then recalculate the time that need to pass and reschedule your alarm.
Set the alarm manager example to trigger a broadcast receiver:
AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
Intent alarmIntent = new Intent(context, MyBroadCastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar = Calendar.getInstance();
// add here your calculate minutes or seconds or hours
calendar.add(Calendar.MINUTE, 45);
if (alarmManager != null) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
Then have your broadcast receiver to handle any other action:
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Do your magic, could be play the video or show a notification saying the video is ready to play
}
}
If you want more information about the alarms in Android, take a look at this link:
https://developer.android.com/training/scheduling/alarms.html