- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我从 https://github.com/youtube/yt-watchme 创建安卓应用程序.
当我尝试使用“CREATE LIVE EVENT”按钮创建 Activity 时。它引发了一些以下错误。我认为这是由于相机权限问题导致的。
错误:
09-17 11:43:53.582 32383-32383/com.google.android.apps.watchme E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.google.android.apps.watchme, PID: 32383
java.lang.NoSuchMethodError: com.google.android.apps.watchme.StreamerActivity.checkSelfPermission
at com.google.android.apps.watchme.StreamerActivity.startStreaming(StreamerActivity.java:174)
at com.google.android.apps.watchme.StreamerActivity.access$200(StreamerActivity.java:46)
at com.google.android.apps.watchme.StreamerActivity$1.onServiceConnected(StreamerActivity.java:63)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1110)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1127)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
任何人请建议。我该如何解决这个问题。
提前致谢
代码更新:
list 文件 XML
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.apps.watchme">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- For authorization. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- For recording audio and video without going to lock. -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission."/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="true"></uses-feature>
<uses-feature
android:name="android.hardware.camera.front"
android:required="true"></uses-feature>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="com.google.android.apps.watchme.MainActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.apps.watchme.StreamerActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"></activity>
<service android:name="com.google.android.apps.watchme.StreamerService" />
</application>
<uses-sdk
android:minSdkVersion="23"
android:targetSdkVersion="23"/>
</manifest>
流 Activity 文件
/*
* Copyright (c) 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.watchme;
import android.Manifest;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.os.Bundle;
import android.os.IBinder;
import android.os.PowerManager;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ToggleButton;
import com.google.android.apps.watchme.util.Utils;
import com.google.android.apps.watchme.util.YouTubeApi;
import java.util.ArrayList;
import java.util.List;
/**
* @author Ibrahim Ulukaya <ulukaya@google.com>
* <p/>
* StreamerActivity class which previews the camera and streams via StreamerService.
*/
public class StreamerActivity extends Activity {
// CONSTANTS
// TODO: Stop hardcoding this and read values from the camera's supported sizes.
public static final int CAMERA_WIDTH = 640;
public static final int CAMERA_HEIGHT = 480;
private static final int REQUEST_CAMERA_MICROPHONE = 0;
// Member variables
private StreamerService streamerService;
private ServiceConnection streamerConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
Log.d(MainActivity.APP_NAME, "onServiceConnected");
streamerService = ((StreamerService.LocalBinder) service).getService();
restoreStateFromService();
startStreaming();
}
@Override
public void onServiceDisconnected(ComponentName className) {
Log.e(MainActivity.APP_NAME, "onServiceDisconnected");
// This should never happen, because our service runs in the same process.
streamerService = null;
}
};
private PowerManager.WakeLock wakeLock;
private Preview preview;
private String rtmpUrl;
private String broadcastId;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(MainActivity.APP_NAME, "onCreate");
super.onCreate(savedInstanceState);
broadcastId = getIntent().getStringExtra(YouTubeApi.BROADCAST_ID_KEY);
//Log.v(MainActivity.APP_NAME, broadcastId);
rtmpUrl = getIntent().getStringExtra(YouTubeApi.RTMP_URL_KEY);
if (rtmpUrl == null) {
Log.w(MainActivity.APP_NAME, "No RTMP URL was passed in; bailing.");
finish();
}
Log.i(MainActivity.APP_NAME, String.format("Got RTMP URL '%s' from calling activity.", rtmpUrl));
setContentView(R.layout.streamer);
preview = (Preview) findViewById(R.id.surfaceViewPreview);
if (!bindService(new Intent(this, StreamerService.class), streamerConnection,
BIND_AUTO_CREATE | BIND_DEBUG_UNBIND)) {
Log.e(MainActivity.APP_NAME, "Failed to bind StreamerService!");
}
final ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleBroadcasting);
toggleButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (toggleButton.isChecked()) {
streamerService.startStreaming(rtmpUrl);
} else {
streamerService.stopStreaming();
}
}
});
}
@Override
protected void onResume() {
Log.d(MainActivity.APP_NAME, "onResume");
super.onResume();
if (streamerService != null) {
restoreStateFromService();
}
}
@Override
protected void onPause() {
Log.d(MainActivity.APP_NAME, "onPause");
super.onPause();
if (preview != null) {
preview.setCamera(null);
}
if (streamerService != null) {
streamerService.releaseCamera();
}
}
@Override
protected void onDestroy() {
Log.d(MainActivity.APP_NAME, "onDestroy");
super.onDestroy();
if (streamerConnection != null) {
unbindService(streamerConnection);
}
stopStreaming();
if (streamerService != null) {
streamerService.releaseCamera();
}
}
private void restoreStateFromService() {
preview.setCamera(Utils.getCamera(Camera.CameraInfo.CAMERA_FACING_FRONT));
}
private void startStreaming() {
Log.d(MainActivity.APP_NAME, "startStreaming");
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, this.getClass().getName());
wakeLock.acquire();
if (!streamerService.isStreaming()) {
String cameraPermission = Manifest.permission.CAMERA;
String microphonePermission = Manifest.permission.RECORD_AUDIO;
int hasCamPermission = checkSelfPermission(cameraPermission);
int hasMicPermission = checkSelfPermission(microphonePermission);
List<String> permissions = new ArrayList<String>();
if (hasCamPermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(cameraPermission);
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.CAMERA)) {
// Provide rationale in Snackbar to request permission
Snackbar.make(preview, R.string.permission_camera_rationale,
Snackbar.LENGTH_INDEFINITE).show();
} else {
// Explain in Snackbar to turn on permission in settings
Snackbar.make(preview, R.string.permission_camera_explain,
Snackbar.LENGTH_INDEFINITE).show();
}
}
if (hasMicPermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(microphonePermission);
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.RECORD_AUDIO)) {
// Provide rationale in Snackbar to request permission
Snackbar.make(preview, R.string.permission_microphone_rationale,
Snackbar.LENGTH_INDEFINITE).show();
} else {
// Explain in Snackbar to turn on permission in settings
Snackbar.make(preview, R.string.permission_microphone_explain,
Snackbar.LENGTH_INDEFINITE).show();
}
}
if (!permissions.isEmpty()) {
String[] params = permissions.toArray(new String[permissions.size()]);
ActivityCompat.requestPermissions(this, params, REQUEST_CAMERA_MICROPHONE);
} else {
// We already have permission, so handle as normal
streamerService.startStreaming(rtmpUrl);
}
}
}
/**
* Callback received when a permissions request has been completed.
*/
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case REQUEST_CAMERA_MICROPHONE: {
Log.i(MainActivity.APP_NAME, "Received response for camera with mic permissions request.");
// We have requested multiple permissions for contacts, so all of them need to be
// checked.
if (Utils.verifyPermissions(grantResults)) {
// permissions were granted, yay! do the
// streamer task you need to do.
streamerService.startStreaming(rtmpUrl);
} else {
Log.i(MainActivity.APP_NAME, "Camera with mic permissions were NOT granted.");
Snackbar.make(preview, R.string.permissions_not_granted,
Snackbar.LENGTH_SHORT)
.show();
}
break;
}
// other 'switch' lines to check for other
// permissions this app might request
}
return;
}
private void stopStreaming() {
Log.d(MainActivity.APP_NAME, "stopStreaming");
if (wakeLock != null) {
wakeLock.release();
wakeLock = null;
}
if (streamerService.isStreaming()) {
streamerService.stopStreaming();
}
}
public void endEvent(View view) {
Intent data = new Intent();
data.putExtra(YouTubeApi.BROADCAST_ID_KEY, broadcastId);
if (getParent() == null) {
setResult(Activity.RESULT_OK, data);
} else {
getParent().setResult(Activity.RESULT_OK, data);
}
finish();
}
}
更新错误代码:
08:57:14.447 18829-18829/com.google.android.apps.watchme E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.google.android.apps.watchme, PID: 18829
java.lang.UnsatisfiedLinkError: Couldn't load ffmpeg from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.google.android.apps.watchme-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.google.android.apps.watchme-1, /vendor/lib, /system/lib]]]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at com.google.android.apps.watchme.Ffmpeg.<clinit>(Ffmpeg.java:26)
at com.google.android.apps.watchme.VideoStreamingConnection.open(VideoStreamingConnection.java:71)
at com.google.android.apps.watchme.StreamerService.startStreaming(StreamerService.java:80)
at com.google.android.apps.watchme.StreamerActivity.startStreaming(StreamerActivity.java:212)
at com.google.android.apps.watchme.StreamerActivity.access$200(StreamerActivity.java:47)
at com.google.android.apps.watchme.StreamerActivity$1.onServiceConnected(StreamerActivity.java:64)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1110)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1127)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
最佳答案
在调用发生的 Activity 代码中,用支票将其包装起来:
int hasCamPermission = checkSelfPermission(cameraPermission);
int hasMicPermission = checkSelfPermission(microphonePermission);
首先在StreamerActivity中添加如下方法:
private boolean shouldCheckForPermission() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}
将这些行更改为:
int hasCamPermission = shouldCheckForPermission() ? checkSelfPermission(cameraPermission) : PackageManager.PERMISSION_GRANTED;
int hasMicPermission = shouldCheckForPermission() ? checkSelfPermission(microphonePermission) : PackageManager.PERMISSION_GRANTED;
为此,您需要使用 SDK 23 进行编译和定位,如我在上面的回答中所述。
关于android - Youtube Watch Me Android 应用程序意外关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32623792/
我正在使用的网站上有一个非 Canvas 导航。关闭 Canvas 导航的默认状态是关闭的,这在移动网站上运行良好,因为您可以打开它并选择您的链接,但在桌面上关闭它并打开它会隐藏用户的信息,我希望它是
我有一个 NSViewController 是这样连接的: 在底部 viewController 中,我尝试使用 self.dismiss(self) 关闭它,但是,它会产生此错误: [General
我昨天制作了一个扩展的 JQuery 搜索框,它的作用就像一个魅力!但是,我在创建一个脚本时遇到问题,当用户单击搜索框时,它会关闭。 这是我的 JQuery: function expandSearc
我一辈子都无法在 API V3 中一次只显示一个信息窗口。我需要一个在下一次开放之前关闭。还希望在 map 上的任何地方关闭 infoWindow onclick。这是否在初始化函数中? 这是我的完整
关闭和清理套接字的正确方法是什么? 我在辅助线程中运行 io_service,我需要关闭与主线程的连接: void closeConnection() { ioc.post([&socket]
我的 Selenium 测试看起来像这样:客户选择金融产品,填写一些必要的数据,并在打印预览中显示条款/协议(protocol)文档(根据本地法律的要求)。打印/关闭打印预览对话框后,客户输入更多数据
我目前正在从 android 网站了解 Navigation Drawer,我正在使用他们的示例 http://developer.android.com/training/implementing-
尝试通过 expo 在模拟器上运行 react-native 应用程序时出现此错误。 Couldn't start project on Android: Error running adb: adb
方法一 function transform(ar) { var alStr = []; for(var i=0; i
我想按以下方式自定义我的抽屉导航: 我希望在抽屉打开时显示一个图标,在抽屉关闭时显示另一个图标,而不是将菜单图标稍微向左滑动的当前默认动画。 关于我在哪里可以找到类似内容的任何想法/线索? 我做了一些
我们刚刚从 0.6.2 或 0.7 升级了我们的 dropwizard 版本,发现 .yml 文件中的很多配置都发生了变化。尽管我们能够弄清楚其中的大部分,但我们无法弄清楚如何关闭“requestLo
从 celery 2.4.5 升级后,我开始让 celery 随机关闭。 我在 centOS 机器上使用 celery 3.0.12、boto 2.6 和 amazon sqs 和 django 1.
我试图包含一些语句来指导用户更多地了解文件无法打开或关闭的原因。文件在写入模式下无法打开的一些可能情况是什么?无法关闭怎么办? FILE *fp; if(!(fp = fopen("testing",
我有一个DLL,可以访问数据库并从存储在配置文件中的应用程序设置中读取连接字符串。然后,引用此DLL的应用程序将需要在其配置文件中为此配置设置设置值。 我遇到的问题是,生成的配置代码会通过Defaul
我将 UIDatePicker 添加为 UITextField 的输入 View UIDatePicker *oBirth; NSDateFormatter *dateFormat; _edit
我有以下代码: SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondVie
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
通常,按下 option 键关闭窗口会关闭应用程序中的所有窗口。在我的应用程序中,我希望它仅关闭与用户正在关闭的窗口相关的窗口。我怎样才能做到这一点?我可以为所有窗口实现 windowShouldCl
我有一个 NSWindow,它托管一个已连接到脚本处理程序的 WebView。 现在,当用户单击 WebView 上的控件上的按钮时,它会调用我的对象上的 Objective C 方法。 在这种特定情
我想根据 MBP 上的相机使用情况自动化个人工作流程。 基本上我想知道是否任何 的摄像头(内置或 USB)已打开或关闭,因此我可以运行我将创建的程序或脚本。 我认为如果我需要轮询相机状态也可以,但基于
我是一名优秀的程序员,十分优秀!