Unreal Engine 4使用C++(低级别)从链接中加载视频

发布于 2025-01-20 20:29:14 字数 1678 浏览 1 评论 0原文

我正在尝试使用链接在媒体播放器中加载视频 这是我的C ++编码,如果您有任何想法,请给我建议

UMediaTexture* MyTexture = NewObject<UMediaTexture>(this);
UStreamMediaSource* streamMediaSource = NewObject<UStreamMediaSource>(this);
    
UMediaPlayer* mediaPlayer = NewObject<UMediaPlayer>(this);
mediaPlayer->StreamUrl("https://docs.unrealengine.com/4.26/Attachments/WorkingWithMedia/MediaFramework/HowTo/StreamMediaSource/Infiltrator%20Demo.mp4");

mediaPlayer->OpenSource(streamMediaSource);
    MyTexture->SetMediaPlayer(mediaPlayer);
    MyTexture->UpdateResource();

    mediaPlayer->Play();

    

Mesh->SetMaterial(0, UnrealMaterial);
    DynamicMaterial = UMaterialInstanceDynamic::Create(UnrealMaterial, this);

    if (DynamicMaterial != nullptr)
    {        
        Mesh->SetMaterial(0, DynamicMaterial);
        DynamicMaterial->SetScalarParameterValue(TEXT("EmissiveStrength"), 50);
        DynamicMaterial->SetTextureParameterValue(TEXT("Param"), MyTexture);
    }

,并尝试其他方式,例如:

UMaterialExpressionTextureSample* TextureExpression = NewObject<UMaterialExpressionTextureSample>(UnrealMaterial);
    TextureExpression->Texture = MyTexture;
    TextureExpression->SamplerType = SAMPLERTYPE_External;
    UnrealMaterial->Expressions.Add(TextureExpression);
    UnrealMaterial->BaseColor.Expression = TextureExpression;

创建动态材料将C ++文件转换为蓝图,但视频不加载,其他方式我们使用Create BluePrint和C ++文件中的设置纹理示例,例如

DynamicMaterial->SetScalarParameterValue(TEXT("EmissiveStrength"), 50);
            DynamicMaterial->SetTextureParameterValue(TEXT("Param"), MyTexture);

请帮我

i am try to load video in media player using link but we can`t play video in low level(C++) but high level(BluePrint) is working fine
here is my C++ coding please if you have any idea give me suggestion

UMediaTexture* MyTexture = NewObject<UMediaTexture>(this);
UStreamMediaSource* streamMediaSource = NewObject<UStreamMediaSource>(this);
    
UMediaPlayer* mediaPlayer = NewObject<UMediaPlayer>(this);
mediaPlayer->StreamUrl("https://docs.unrealengine.com/4.26/Attachments/WorkingWithMedia/MediaFramework/HowTo/StreamMediaSource/Infiltrator%20Demo.mp4");

mediaPlayer->OpenSource(streamMediaSource);
    MyTexture->SetMediaPlayer(mediaPlayer);
    MyTexture->UpdateResource();

    mediaPlayer->Play();

    

Mesh->SetMaterial(0, UnrealMaterial);
    DynamicMaterial = UMaterialInstanceDynamic::Create(UnrealMaterial, this);

    if (DynamicMaterial != nullptr)
    {        
        Mesh->SetMaterial(0, DynamicMaterial);
        DynamicMaterial->SetScalarParameterValue(TEXT("EmissiveStrength"), 50);
        DynamicMaterial->SetTextureParameterValue(TEXT("Param"), MyTexture);
    }

and try also other way like:

UMaterialExpressionTextureSample* TextureExpression = NewObject<UMaterialExpressionTextureSample>(UnrealMaterial);
    TextureExpression->Texture = MyTexture;
    TextureExpression->SamplerType = SAMPLERTYPE_External;
    UnrealMaterial->Expressions.Add(TextureExpression);
    UnrealMaterial->BaseColor.Expression = TextureExpression;

and create Dynamic Material convert c++ file to Blueprint but video not load and other way we uses create blueprint and set texture sample uses in c++ file like

DynamicMaterial->SetScalarParameterValue(TEXT("EmissiveStrength"), 50);
            DynamicMaterial->SetTextureParameterValue(TEXT("Param"), MyTexture);

please help me out

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以可爱出名 2025-01-27 20:29:14

您的代码中可能存在一些错误。
试试这个。

UMediaTexture* MyTexture = NewObject<UMediaTexture>(this);
UStreamMediaSource* streamMediaSource = NewObject<UStreamMediaSource>(this);
    
UMediaPlayer* mediaPlayer = NewObject<UMediaPlayer>(this);
streamMediaSource->StreamUrl = "https://docs.unrealengine.com/4.26/Attachments/WorkingWithMedia/MediaFramework/HowTo/StreamMediaSource/Infiltrator%20Demo.mp4";

mediaPlayer->OpenSource(streamMediaSource);
    MyTexture->SetMediaPlayer(mediaPlayer);
    MyTexture->UpdateResource();

    mediaPlayer->Play();

Here is some error in your code maybe.
Try this.

UMediaTexture* MyTexture = NewObject<UMediaTexture>(this);
UStreamMediaSource* streamMediaSource = NewObject<UStreamMediaSource>(this);
    
UMediaPlayer* mediaPlayer = NewObject<UMediaPlayer>(this);
streamMediaSource->StreamUrl = "https://docs.unrealengine.com/4.26/Attachments/WorkingWithMedia/MediaFramework/HowTo/StreamMediaSource/Infiltrator%20Demo.mp4";

mediaPlayer->OpenSource(streamMediaSource);
    MyTexture->SetMediaPlayer(mediaPlayer);
    MyTexture->UpdateResource();

    mediaPlayer->Play();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文