playLastPosition method
يتابع التشغيل الصوتي من الموضع الأخير الذي توقف عنده المستخدم. هذه الدالة مفيدة جداً لتوفير تجربة مستخدم سلسة حيث يمكن للمستخدم الاستمرار من حيث توقف. تقوم بتحميل المصدر الصوتي الأخير وبدء التشغيل من الموضع المحفوظ تلقائياً.
يتم حفظ الموضع الأخير تلقائياً عند إيقاف التشغيل أو إغلاق التطبيق.
Continues audio playback from the last position where the user stopped. This function is very useful for providing a smooth user experience where the user can continue from where they left off. It loads the last audio source and automatically starts playing from the saved position.
The last position is automatically saved when stopping playback or closing the app.
مثال للاستخدام / Example usage:
// تشغيل من الموضع الأخير
// Play from last position
await quranLibrary().playLastPosition();
// مع معالجة الأخطاء
// With error handling
try {
await quranLibrary().playLastPosition();
print('تم استئناف التشغيل من الموضع الأخير');
} catch (e) {
print('خطأ في تشغيل الموضع الأخير: $e');
}
// في زر واجهة المستخدم
// In UI button
ElevatedButton(
onPressed: () => quranLibrary().playLastPosition(),
child: Text('متابعة من حيث توقفت'),
),
Implementation
Future<void> playLastPosition() async => await AudioCtrl.instance
.lastAudioSource()
.then((_) => AudioCtrl.instance.state.audioPlayer.play());