修复windows无法播放视频
This commit is contained in:
parent
ee63a10c19
commit
2776c587c1
@ -33,8 +33,13 @@ class VideoManager:
|
||||
|
||||
# 创建视频纹理
|
||||
if video_path and os.path.exists(video_path):
|
||||
# Convert Windows path to Panda3D compatible path format
|
||||
from panda3d.core import Filename
|
||||
panda_path = Filename.fromOsSpecific(video_path)
|
||||
converted_path = str(panda_path)
|
||||
|
||||
movie_texture = MovieTexture(name)
|
||||
success = movie_texture.read(video_path)
|
||||
success = movie_texture.read(converted_path)
|
||||
|
||||
if success:
|
||||
video_screen.setTexture(movie_texture)
|
||||
@ -43,7 +48,7 @@ class VideoManager:
|
||||
video_obj = {
|
||||
'node': video_screen,
|
||||
'texture': movie_texture,
|
||||
'path': video_path,
|
||||
'path': converted_path,
|
||||
'name': name,
|
||||
'type': 'movie',
|
||||
'is_playing': False
|
||||
@ -62,7 +67,7 @@ class VideoManager:
|
||||
print(f"✓ 视频屏幕创建成功: {name}")
|
||||
return video_screen
|
||||
else:
|
||||
print(f"✗ 无法加载视频: {video_path}")
|
||||
print(f"✗ 无法加载视频: {converted_path}")
|
||||
# 创建占位符纹理
|
||||
self._create_placeholder_texture(video_screen, name)
|
||||
else:
|
||||
@ -103,8 +108,13 @@ class VideoManager:
|
||||
|
||||
# 创建视频纹理
|
||||
if video_path and os.path.exists(video_path):
|
||||
# Convert Windows path to Panda3D compatible path format
|
||||
from panda3d.core import Filename
|
||||
panda_path = Filename.fromOsSpecific(video_path)
|
||||
converted_path = str(panda_path)
|
||||
|
||||
movie_texture = MovieTexture(name)
|
||||
success = movie_texture.read(video_path)
|
||||
success = movie_texture.read(converted_path)
|
||||
|
||||
if success:
|
||||
sphere.setTexture(movie_texture)
|
||||
@ -113,7 +123,7 @@ class VideoManager:
|
||||
video_obj = {
|
||||
'node': sphere,
|
||||
'texture': movie_texture,
|
||||
'path': video_path,
|
||||
'path': converted_path,
|
||||
'name': name,
|
||||
'type': 'spherical',
|
||||
'is_playing': True
|
||||
|
||||
@ -1375,8 +1375,13 @@ class GUIManager:
|
||||
print(f"❌ 视频文件不存在: {video_path}")
|
||||
return False
|
||||
|
||||
# Convert Windows path to Panda3D compatible path format
|
||||
from panda3d.core import Filename
|
||||
panda_path = Filename.fromOsSpecific(video_path)
|
||||
converted_path = str(panda_path)
|
||||
|
||||
# 加载新的视频纹理
|
||||
movie_texture = self._loadMovieTexture(video_path)
|
||||
movie_texture = self._loadMovieTexture(video_path) # Pass original path for existence check
|
||||
if movie_texture:
|
||||
# 清除现有的纹理
|
||||
video_screen.clearTexture()
|
||||
@ -1405,15 +1410,15 @@ class GUIManager:
|
||||
|
||||
# 保存新的视频纹理引用到PythonTag
|
||||
video_screen.setPythonTag("movie_texture", movie_texture)
|
||||
video_screen.setTag("video_path", video_path)
|
||||
video_screen.setTag("video_path", converted_path) # Store converted path
|
||||
|
||||
# 确保视频屏幕有正确的材质
|
||||
self._ensureVideoScreenMaterial(video_screen)
|
||||
|
||||
print(f"✅ 成功加载新视频: {video_path}")
|
||||
print(f"✅ 成功加载新视频: {converted_path}")
|
||||
return True
|
||||
else:
|
||||
print(f"❌ 无法加载视频文件: {video_path}")
|
||||
print(f"❌ 无法加载视频文件: {converted_path}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
@ -1425,7 +1430,7 @@ class GUIManager:
|
||||
def _loadMovieTexture(self, video_path):
|
||||
"""加载视频纹理的兼容方法"""
|
||||
try:
|
||||
from panda3d.core import Texture, MovieTexture
|
||||
from panda3d.core import Texture, MovieTexture, Filename
|
||||
import os
|
||||
|
||||
# 检查文件是否存在
|
||||
@ -1433,12 +1438,16 @@ class GUIManager:
|
||||
print(f"❌ 视频文件不存在: {video_path}")
|
||||
return None
|
||||
|
||||
print(f"🔍 尝试加载视频文件: {video_path}")
|
||||
# Convert Windows path to Panda3D compatible path format
|
||||
panda_path = Filename.fromOsSpecific(video_path)
|
||||
converted_path = str(panda_path)
|
||||
|
||||
print(f"🔍 尝试加载视频文件: {converted_path}")
|
||||
|
||||
# 方法1: 尝试使用 MovieTexture(专门用于视频)
|
||||
try:
|
||||
movie_texture = MovieTexture(video_path)
|
||||
if movie_texture.read(video_path):
|
||||
movie_texture = MovieTexture(converted_path)
|
||||
if movie_texture.read(converted_path):
|
||||
print("✅ 使用 MovieTexture 成功加载视频")
|
||||
self._configureVideoTexture(movie_texture)
|
||||
return movie_texture
|
||||
@ -1449,7 +1458,7 @@ class GUIManager:
|
||||
|
||||
# 方法2: 尝试使用 loader.loadTexture
|
||||
try:
|
||||
movie_texture = self.world.loader.loadTexture(video_path)
|
||||
movie_texture = self.world.loader.loadTexture(converted_path)
|
||||
if movie_texture and hasattr(movie_texture, 'is_playable') and movie_texture.is_playable():
|
||||
print("✅ 使用 loader.loadTexture 成功加载视频纹理")
|
||||
self._configureVideoTexture(movie_texture)
|
||||
@ -1462,7 +1471,7 @@ class GUIManager:
|
||||
# 方法3: 尝试使用 Texture.read(作为最后备选)
|
||||
try:
|
||||
texture = Texture()
|
||||
if texture.read(video_path):
|
||||
if texture.read(converted_path):
|
||||
print("✅ 使用 Texture.read 成功加载(可能作为静态纹理)")
|
||||
self._configureVideoTexture(texture)
|
||||
return texture
|
||||
|
||||
@ -836,10 +836,15 @@ class MainApp(ShowBase):
|
||||
return video_screen
|
||||
|
||||
def _loadMovieTexture(self, video_path):
|
||||
from panda3d.core import Texture, MovieTexture
|
||||
from panda3d.core import Texture, MovieTexture, Filename
|
||||
import os
|
||||
movie_texture = MovieTexture(video_path)
|
||||
if movie_texture.read(video_path):
|
||||
|
||||
# Convert Windows path to Panda3D compatible path format
|
||||
panda_path = Filename.fromOsSpecific(video_path)
|
||||
converted_path = str(panda_path)
|
||||
|
||||
movie_texture = MovieTexture(converted_path)
|
||||
if movie_texture.read(converted_path):
|
||||
self._configureVideoTexture(movie_texture)
|
||||
return movie_texture
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user