Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QtMultimediaUtils.java
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4package org.qtproject.qt.android.multimedia;
5
6import android.app.Activity;
7import android.content.Context;
8import android.media.MediaCodecInfo;
9import android.media.MediaCodecList;
10import android.view.OrientationEventListener;
11import android.webkit.MimeTypeMap;
12import android.net.Uri;
13import android.content.ContentResolver;
14import android.os.Environment;
15import android.media.MediaScannerConnection;
16import java.lang.String;
17
18import org.qtproject.qt.android.UsedFromNativeCode;
19
20import java.io.File;
21import android.util.Log;
22
23class QtMultimediaUtils
24{
25 static private class OrientationListener extends OrientationEventListener
26 {
27 static int deviceOrientation = 0;
28
29 OrientationListener(Context context)
30 {
31 super(context);
32 }
33
35 public void onOrientationChanged(int orientation)
36 {
37 if (orientation == ORIENTATION_UNKNOWN)
38 return;
39
40 deviceOrientation = orientation;
41 }
42 }
43
44 static private Context m_context = null;
45 static private OrientationListener m_orientationListener = null;
46 private static final String QtTAG = "Qt QtMultimediaUtils";
47
48 static void setActivity(Activity qtMainActivity, Object qtActivityDelegate)
49 {
50 }
51
52 static void setContext(Context context)
53 {
54 m_context = context;
55 m_orientationListener = new OrientationListener(context);
56 }
57
58 QtMultimediaUtils()
59 {
60 }
61
62 static void enableOrientationListener(boolean enable)
63 {
64 if (enable)
65 m_orientationListener.enable();
66 else
67 m_orientationListener.disable();
68 }
69
70 static int getDeviceOrientation()
71 {
72 return OrientationListener.deviceOrientation;
73 }
74
75 static String getDefaultMediaDirectory(int type)
76 {
77 String dirType = new String();
78 switch (type) {
79 case 0:
80 dirType = Environment.DIRECTORY_MUSIC;
81 break;
82 case 1:
83 dirType = Environment.DIRECTORY_MOVIES;
84 break;
85 case 2:
86 dirType = Environment.DIRECTORY_DCIM;
87 break;
88 default:
89 break;
90 }
91
92 File path = new File("");
93 if (type == 3) {
94 // There is no API for knowing the standard location for sounds
95 // such as voice recording. Though, it's typically in the 'Sounds'
96 // directory at the root of the external storage
97 path = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
98 + File.separator + "Sounds");
99 } else {
100 path = Environment.getExternalStoragePublicDirectory(dirType);
101 }
102
103 path.mkdirs(); // make sure the directory exists
104
105 return path.getAbsolutePath();
106 }
107
108 static void registerMediaFile(String file)
109 {
110 MediaScannerConnection.scanFile(m_context, new String[] { file }, null, null);
111 }
112
113 static File getCacheDirectory() { return m_context.getCacheDir(); }
114
115 /*
116 The array of codecs is in the form:
117 c2.qti.vp9.decoder
118 c2.android.opus.encoder
119 OMX.google.opus.decoder
120 */
121 @UsedFromNativeCode
122 private static String[] getMediaCodecs()
123 {
124 final MediaCodecList codecList = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
125 final MediaCodecInfo[] codecInfoArray = codecList.getCodecInfos();
126 String[] codecs = new String[codecInfoArray.length];
127 for (int i = 0; i < codecInfoArray.length; ++i)
128 codecs[i] = codecInfoArray[i].getName();
129 return codecs;
130 }
131
132 static String getMimeType(Context context, String url)
133 {
134 Uri parsedUri = Uri.parse(url);
135 String type = null;
136
137 try {
138 String scheme = parsedUri.getScheme();
139 if (scheme != null && scheme.contains("content")) {
140 ContentResolver cR = context.getContentResolver();
141 type = cR.getType(parsedUri);
142 } else {
143 String extension = MimeTypeMap.getFileExtensionFromUrl(url);
144 if (extension != null)
145 type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
146 }
147 } catch (Exception e) {
148 Log.e(QtTAG, "getMimeType(): " + e.toString());
149 }
150 return type;
151 }
152}
QPainter Context
static const QString context()
Definition java.cpp:396
const wchar_t * getName(QSslKeyPrivate::Cipher cipher)
GLenum type
GLboolean enable
GLsizei const GLchar *const * path
decltype(openFileForWriting({})) File
Definition main.cpp:76
QUrl url("http://my.server.tld")