I am creating a video player application targeting android 13(API 33). I am using Qt Creator 9.0.1 and qt version is 6.4.0. With the Video component in qml, playing videos from internal storage is working. But I need to play videos from usb, how to do that?
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
I have added the above mentioned permissions in android manifest file. I am also requesting runtime permissions if the permission is not granted.
auto r = QtAndroidPrivate::checkPermission(QtAndroidPrivate::Storage).result();
QtAndroidPrivate::checkPermission(QtAndroidPrivate::Storage).result();
if (r == QtAndroidPrivate::Denied)
{
qDebug()<<"denied";
r = QtAndroidPrivate::requestPermission(QtAndroidPrivate::Storage).result();
if (r == QtAndroidPrivate::Denied)
return false;
}
return true;
Still not able to play videos from usb, What am I missing here?
On Android 13, you don't really need to request those permissions, users need to request permission using the file dialog and for Qt that's under QFileDialog
, so to get access to some video file under the external storage, use https://doc.qt.io/qt-6/qfiledialog.html#getOpenFileName which gets you a file url and you'll able to open and read its content.