Fix a few bugs related to image loading (wrap it all in a try catch lol)
This commit is contained in:
		
							parent
							
								
									0135d84443
								
							
						
					
					
						commit
						e9a07b15da
					
				
					 3 changed files with 30 additions and 16 deletions
				
			
		
							
								
								
									
										11
									
								
								src/main.cpp
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								src/main.cpp
									
										
									
									
									
								
							|  | @ -191,14 +191,22 @@ int main(int argc, char *argv[]) { | |||
|     //     std::cout << *it << std::endl;
 | ||||
|     // }
 | ||||
| 
 | ||||
| 
 | ||||
|     double lasttime = 0.0; | ||||
|     // Main game loop
 | ||||
|     while (!WindowShouldClose() && | ||||
|            run) // Detect window close button or ESC key, or a quit from the menu
 | ||||
|     { | ||||
| 
 | ||||
|         if (GetTime() > lasttime+3 ) { | ||||
|             lasttime = GetTime(); | ||||
|             current_player.Refresh(); | ||||
|         } | ||||
| 
 | ||||
|         BeginDrawing(); | ||||
|         ClearBackground(DARKGRAY); | ||||
| 
 | ||||
| 
 | ||||
|         // start ImGui content
 | ||||
|         rlImGuiBegin(); | ||||
| 
 | ||||
|  | @ -246,9 +254,6 @@ int main(int argc, char *argv[]) { | |||
| 
 | ||||
|         if (ImGui::Begin("Player Control")) { | ||||
|             ImGui::Text("%s", current_player.GetIdentity().c_str()); | ||||
|             ImGui::Text( | ||||
|                 "%s", | ||||
|                 current_player.GetCurrentMetadata()["mpris:artUrl"].get<std::string>().c_str()); | ||||
|             if (ImGui::Button("Prev")) { | ||||
|                 current_player.Prev(); | ||||
|             } | ||||
|  |  | |||
|  | @ -14,16 +14,17 @@ MprisPlayer::MprisPlayer(std::string servicename) { | |||
|     bus_connection = sdbus::createSessionBusConnection(); | ||||
|     sdbus::ServiceName dest{servicename}; | ||||
|     sdbus::ObjectPath objec{"/org/mpris/MediaPlayer2"}; | ||||
| 
 | ||||
|     image_path_cache = "NULL"; | ||||
|     PlayerProxy = sdbus::createProxy(dest, objec); | ||||
|     mp2 = "org.mpris.MediaPlayer2.Player"; | ||||
|     playpause = "PlayPause"; | ||||
|     Refresh(); | ||||
| } | ||||
| 
 | ||||
| void MprisPlayer::PausePlay() { | ||||
|     auto method = PlayerProxy->createMethodCall(mp2, playpause); | ||||
|     auto method = PlayerProxy->createMethodCall(mp2, sdbus::MethodName("PlayPause")); | ||||
|     try { | ||||
|         auto reply = PlayerProxy->callMethod(method); | ||||
|     } catch (const std::exception& e) {} | ||||
| } | ||||
| 
 | ||||
| void MprisPlayer::Next() { | ||||
|  | @ -35,7 +36,9 @@ void MprisPlayer::Next() { | |||
| 
 | ||||
| void MprisPlayer::Prev() { | ||||
|     auto method = PlayerProxy->createMethodCall(mp2, sdbus::MethodName("Previous")); | ||||
|     try { | ||||
|         auto reply = PlayerProxy->callMethod(method); | ||||
|     } catch (const std::exception &e) {} | ||||
| } | ||||
| 
 | ||||
| std::string MprisPlayer::GetIdentity() { | ||||
|  | @ -46,18 +49,23 @@ std::unordered_map<std::string, sdbus::Variant> MprisPlayer::GetCurrentMetadata( | |||
|     return current_metadata; | ||||
| } | ||||
| void MprisPlayer::Refresh() { | ||||
|     try { | ||||
|         identity = PlayerProxy->getProperty("Identity") | ||||
|                        .onInterface("org.mpris.MediaPlayer2") | ||||
|                        .get<std::string>(); | ||||
|         current_metadata = PlayerProxy->getProperty("Metadata") | ||||
|                                .onInterface("org.mpris.MediaPlayer2.Player") | ||||
|                                .get<std::unordered_map<std::string, sdbus::Variant>>(); | ||||
|         if (current_metadata["mpris:artUrl"].get<std::string>() != image_path_cache) { | ||||
|             image_path_cache = current_metadata["mpris:artUrl"].get<std::string>(); | ||||
|             UpdateTexture(); | ||||
|         } | ||||
|     } catch (const std::exception& e) {} | ||||
|     return; | ||||
| } | ||||
| 
 | ||||
| void MprisPlayer::UpdateTexture() { | ||||
|     auto metadata = GetCurrentMetadata(); | ||||
|     std::string filename = metadata["mpris:artUrl"].get<std::string>(); | ||||
|     std::string filename = image_path_cache; | ||||
|     if (filename.length() > 0) { | ||||
|         if (filename.c_str()[0] == 'f') { | ||||
|             std::cout << "parsing as file" << std::endl; | ||||
|  |  | |||
|  | @ -29,6 +29,7 @@ class MprisPlayer { | |||
|     sdbus::InterfaceName mp2; | ||||
|     sdbus::MethodName playpause; | ||||
|     RayTexture tex; | ||||
|     std::string image_path_cache; | ||||
|     explicit MprisPlayer(std::string servicename); | ||||
|     void PausePlay(); | ||||
|     void Refresh(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue