我在模拟器中使用了Android 10 AVD。我将示例视频文件(“ sample.mp4”)复制到模拟器,然后尝试播放。该活动具有一个VideoView
和一个Button
。单击按钮时,我尝试播放视频,但由于“权限被拒绝”而失败。当然,我已经添加了“外部存储读取”权限,并在“应用信息”中手动启用了该权限。但是由于它不起作用,我还添加了requestPermissions()
并在运行时启用了权限。两者都不起作用。
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button.setOnClickListener {
videoView.setVideoPath("/sdcard/Download/sample.mp4");
videoView.start();
}
val permissions = arrayOf<String>(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE
)
requestPermissions(permissions, 2222)
错误消息:
W/VideoView: Unable to open content: /sdcard/Download/sample.mp4
java.io.FileNotFoundException: /sdcard/Download/sample.mp4: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:496)
这不是因为路径错误,而是因为当我给出伪路径时,错误有所不同。
Unable to open content: /sdcard/Download/samplexxx.mp4
java.io.FileNotFoundException: /sdcard/Download/samplexxx.mp4: open failed: ENOENT (No such file or directory)
通过/storage/emulated/0/Download/sample.mp4
给了我同样的“权限被拒绝”错误。
答案 0 :(得分:0)
尝试使用此代码获得访问权限
#11 /code/community_api/vendor/laravel/framework/src/Illuminate/Container/Container.php(1031): Illuminate\Foundation\Providers\FoundationServiceProvider->Illuminate\Foundation\Providers\{closure}(Object(App\Modules\Auth\Requests\DeleteUserRequest), Object(Illuminate\Foundation\Application))
#12 /code/community_api/vendor/laravel/framework/src/Illuminate/Container/Container.php(994): Illuminate\Container\Container->fireCallbackArray(Object(App\Modules\Auth\Requests\DeleteUserRequest), Array)
#13 /code/community_api/vendor/laravel/framework/src/Illuminate/Container/Container.php(648): Illuminate\Container\Container->fireResolvingCallbacks('App\\Modules\\Aut...', Object(App\Modules\Auth\Requests\DeleteUserRequest))
#14 /code/community_api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(697): Illuminate\Container\Container->make('App\\Modules\\Aut...', Array)
#15 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/RouteDependencyResolverTrait.php(85): Illuminate\Foundation\Application->make('App\\Modules\\Aut...')
#16 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/RouteDependencyResolverTrait.php(58): Illuminate\Routing\ControllerDispatcher->transformDependency(Object(ReflectionParameter), Array, Array)
#17 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/RouteDependencyResolverTrait.php(41): Illuminate\Routing\ControllerDispatcher->resolveMethodDependencies(Array, Object(ReflectionMethod))
#18 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(143): Illuminate\Routing\ControllerDispatcher->resolveClassMethodDependencies(Array, Object(App\Modules\Auth\Controllers\UserController), 'deleteCompanyUs...')
#19 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(94): Illuminate\Routing\ControllerDispatcher->call(Object(App\Modules\Auth\Controllers\UserController), Object(Illuminate\Routing\Route), 'deleteCompanyUs...')
#20 [internal function]: Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#21 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#22 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#23 /code/community_api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#24 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(96): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#25 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(54): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(App\Modules\Auth\Controllers\UserController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'deleteCompanyUs...')
#26 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(174): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'App\\Modules\\Aut...', 'deleteCompanyUs...')
#27 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(140): Illuminate\Routing\Route->runController(Object(Illuminate\Http\Request))
#28 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(724): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#29 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#30 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#31 /code/community_api/app/Http/Middleware/Api.php(30): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#32 [internal function]: App\Http\Middleware\Api->handle(Object(Illuminate\Http\Request), Object(Closure))
#33 /code/community_api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(136): call_user_func_array(Array, Array)
#34 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#35 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#36 /code/community_api/vendor/tymon/jwt-auth/src/Middleware/RefreshToken.php(28): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#37 [internal function]: Tymon\JWTAuth\Middleware\RefreshToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#38 /code/community_api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(136): call_user_func_array(Array, Array)
#39 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#40 /code/community_api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#41 /code/community_api/vendor/tymon/jwt-auth/src/Middleware/GetUserFromToken.php(46): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))