增加多屏显示,视频播放
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "MyActor.h"
|
||||
|
||||
// Sets default values
|
||||
AMyActor::AMyActor()
|
||||
{
|
||||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void AMyActor::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void AMyActor::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
#include "MyBlueprintFunctionLibrary.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmdeviceapi.h>
|
||||
#include <endpointvolume.h>
|
||||
#include <audioclient.h>
|
||||
#include <iostream>
|
||||
#pragma comment(lib, "ole32.lib")
|
||||
|
||||
// 获取当前系统音量
|
||||
float _GetSystemVolume() {
|
||||
HRESULT hr;
|
||||
IMMDeviceEnumerator* pEnumerator = NULL;
|
||||
IMMDevice* pDevice = NULL;
|
||||
IAudioEndpointVolume* pEndpointVolume = NULL;
|
||||
float currentVolume = 0.0f;
|
||||
|
||||
// 初始化COM库
|
||||
hr = CoInitialize(NULL);
|
||||
if (FAILED(hr)) {
|
||||
UE_LOG(LogTemp, Warning, TEXT("COM初始化失败"));
|
||||
return -1.0f;
|
||||
}
|
||||
|
||||
// 创建设备枚举器
|
||||
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL,
|
||||
__uuidof(IMMDeviceEnumerator), (void**)&pEnumerator);
|
||||
if (FAILED(hr)) {
|
||||
UE_LOG(LogTemp, Warning, TEXT("创建设备枚举器失败"));
|
||||
CoUninitialize();
|
||||
return -1.0f;
|
||||
}
|
||||
|
||||
// 获取默认音频端点
|
||||
hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
|
||||
if (FAILED(hr)) {
|
||||
UE_LOG(LogTemp, Warning, TEXT("获取默认音频端点失败"));
|
||||
pEnumerator->Release();
|
||||
CoUninitialize();
|
||||
return -1.0f;
|
||||
}
|
||||
|
||||
// 激活音频端点音量接口
|
||||
hr = pDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL, (void**)&pEndpointVolume);
|
||||
if (FAILED(hr)) {
|
||||
UE_LOG(LogTemp, Warning, TEXT("激活音频端点音量接口失败"));
|
||||
pDevice->Release();
|
||||
pEnumerator->Release();
|
||||
CoUninitialize();
|
||||
return -1.0f;
|
||||
}
|
||||
|
||||
// 获取当前音量
|
||||
hr = pEndpointVolume->GetMasterVolumeLevelScalar(¤tVolume);
|
||||
if (FAILED(hr)) {
|
||||
UE_LOG(LogTemp, Warning, TEXT("获取音量失败"));
|
||||
}
|
||||
|
||||
// 释放资源
|
||||
pEndpointVolume->Release();
|
||||
pDevice->Release();
|
||||
pEnumerator->Release();
|
||||
CoUninitialize();
|
||||
|
||||
return currentVolume;
|
||||
}
|
||||
|
||||
// 设置系统音量
|
||||
bool _SetSystemVolume(float volume) {
|
||||
HRESULT hr;
|
||||
IMMDeviceEnumerator* pEnumerator = NULL;
|
||||
IMMDevice* pDevice = NULL;
|
||||
IAudioEndpointVolume* pEndpointVolume = NULL;
|
||||
|
||||
// 初始化COM库
|
||||
hr = CoInitialize(NULL);
|
||||
if (FAILED(hr)) {
|
||||
UE_LOG(LogTemp, Warning, TEXT("COM初始化失败"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// 创建设备枚举器
|
||||
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL,
|
||||
__uuidof(IMMDeviceEnumerator), (void**)&pEnumerator);
|
||||
if (FAILED(hr)) {
|
||||
UE_LOG(LogTemp, Warning, TEXT("创建设备枚举器失败"));
|
||||
CoUninitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取默认音频端点
|
||||
hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
|
||||
if (FAILED(hr)) {
|
||||
UE_LOG(LogTemp, Warning, TEXT("获取默认音频端点失败"));
|
||||
pEnumerator->Release();
|
||||
CoUninitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
// 激活音频端点音量接口
|
||||
hr = pDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL, (void**)&pEndpointVolume);
|
||||
if (FAILED(hr)) {
|
||||
UE_LOG(LogTemp, Warning, TEXT("激活音频端点音量接口失败"));
|
||||
pDevice->Release();
|
||||
pEnumerator->Release();
|
||||
CoUninitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
// 设置音量
|
||||
hr = pEndpointVolume->SetMasterVolumeLevelScalar(volume, NULL);
|
||||
if (FAILED(hr)) {
|
||||
UE_LOG(LogTemp, Warning, TEXT("设置音量失败"));
|
||||
}
|
||||
|
||||
// 释放资源
|
||||
pEndpointVolume->Release();
|
||||
pDevice->Release();
|
||||
pEnumerator->Release();
|
||||
CoUninitialize();
|
||||
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
bool UMyBlueprintFunctionLibrary::SetSystemVolume(float volume)
|
||||
{
|
||||
return _SetSystemVolume(volume);
|
||||
}
|
||||
|
||||
float UMyBlueprintFunctionLibrary::GetSystemVolume()
|
||||
{
|
||||
return _GetSystemVolume();
|
||||
}
|
||||
Reference in New Issue
Block a user