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